Shell Programming and Scripting

# set date to your spec: this is month/day/yr/hr/min/sec:

sysdate=`date '+%m/%d/%Y-%H:%M:%S'`
# get the last line before the history file is modified
tail -1 /tmp/hosthistory.txt |while read lastdate mydevices
do
         echo $lastdate
      echo $mydevices
done
LIST = 'ypcat hosts|| sort | awk '{print $2}''
for Devices in $LIST
do
   Errorcount=`snmpget -v1 -c privator $Devices   snmpInBadCommunityNames.O |awk '{print $4}' `
    if [ Errorcount > 0 ]; then
      Devices=$Errorcount
      echo $Devices
      # line added
      echo "$sysdate $Devices" >> /tmp/hosthistory.txt
else
      Errorcount=`snmpget -v1 -c pubilc $Devices    snmpInBadCommunityNames.O |awk '{print $4}' `
      if [ Errorcount > 0 ]; then
        # line added
        echo "$sysdate $Devices" >> /tmp/hosthistory.txt
        Devices=$Errorcount
      else
         echo "error"
      fi
   fi
done

the result shows the devices with their errorcount.i like to be able to check if the devices community names is "privator" then the device should should show equal to zero, otherwise show me the number of hits that soeone try to hack the device.Please advices or help!!!!

it's illegible

Thanks
but what do u mean"its illegal"

all i wanted to know if there is someone who is trying to hack my devices.
thats all
if there any command i can use to see if if my device is been hacked or not.
Thanks lemseffer

---------- Post updated at 12:04 PM ---------- Previous update was at 12:03 PM ----------

alor vous parler fancais

first , i just want to thank you for your advice

Let me paraphrase my question:
I need to automate the following process:

I have a list of devices in a file called host.txt, I need to take that list and run the command

snmpget -v 1 -c private devices snmpget InBadCommunityNames.0 !!!

for each device to see if its running snmpget, I want to the create a file for any device that is running snmpand ofcourse return zero.

I am new to scripting so any help would be appreciated. This is for a solaris box, and KSH.

Thanks

the free tool: (MRTG - Tobi Oetiker's MRTG - The Multi Router Traffic Grapher) maybe give you more help in your case.

thanks rdcwayx, but i'm looking for a code to help me get this result
not a tool.

Thanks

---------- Post updated at 08:36 AM ---------- Previous update was at 07:59 AM ----------

good morning all,

here is what i did :

LIST = 'ypcat hosts|| sort | awk '{print $2}''
for Devices in $LIST
do
  Errorcount=`snmpget -v1 -c privator $Devices snmpInBadCommunityNames.O |awk '{print $4}' `
  if [ Errorcount > 0 ]; then
    Devices=$Errorcount
    echo $Devices
#   line added
    echo "$sysdate $Devices" >> /tmp/hosthistory.txt
  fi
done

but the answer is wrong cause i get the errorcount.
i want to be able to see all the devices equal to zero if the community name is privator

thanks for your help

---------- Post updated at 03:58 PM ---------- Previous update was at 08:36 AM ----------

hello all,

i want to Perform an SNMP set request in SNMP agent. return 0 if the connect succeeded.

here is what i did :
LIST = 'ypcat hosts|| sort | awk '{print $2}''
for Devices in $LIST
do
Errorcount=`snmpget -v1 -c privator $Devices snmpInBadCommunityNames.O |awk '{print $4}' `
if [ Errorcount > 0 ]; then
Devices=$Errorcount
echo $Devices
# line added
echo "$sysdate $Devices" >> /tmp/hosthistory.txt

fi
done

but the answer is wrong cause i'm getting an errorcount.

Hi lemseffert, I noticed a few errors on this line:

LIST = 'ypcat hosts|| sort | awk '{print $2}''

=>

LIST=$(ypcat hosts | sort | awk '{print $2}')

also

if [ Errorcount > 0 ]; then

=>

if [ $Errorcount -gt 0 ]; then

I have not really looked at the loop itself.

something to start with - not sure what you're after though. I'm not sure why you need to 'sort' either...
Where do you assign value to 'sysdate'?
You're not doing an 'snmpset' - you're GETting and SNMP var:

#!/bin/ksh

sysdate=$(date)

ypcat hosts | while read junk device junk
do
  Errorcount=$(snmpget -v1 -c privator "${device}" snmpInBadCommunityNames.O |awk '{print $4}')
  if [ "${Errorcount}" -gt 0 ]; then
     echo ${device}
     # line added
     echo "$sysdate ${device}" >> /tmp/hosthistory.txt
  fi
done

Thank you cgersh99
actually what i'm looking for is check devices for community name if if the community name is correct return 0 if not return 1.

Thanks again

If your 'snmpget' is a reliable one (i.e. returning non-zero values for the wrong community string), try getting 'sysName' off of a device like so:

#!/bin/ksh

sysdate=$(date)

ypcat hosts | while read junk device junk
do
  snmpget -v1 -c privator "${device}" sysName.0  > dev/null
  if [ "${?}" -ne 0 ]; then
     echo ${device}
     # line added
     echo "$sysdate ${device}" >> /tmp/hosthistory.txt
  fi
done

here is what i did

LIST = 'ypcat hosts| sort | awk '{print $2}''
for Devices in $LIST
do
value=`snmpget -v1 -c privator $Devices snmpInBadCommunityNames.O |awk '{print $4}' `
if [ Errorcount >= 0 ]; then

echo $Devices=0
# line added
echo "$Devices" >> /tmp/hosthistory.txt

fi
done

but i feel that i'm forcing the value of the device to be zero
I still dont think its doing what i wanted to do and get as a result.
i want to Perform an SNMP set or get request in SNMP device. return 0 if the connect succeeded.return 1 if the connect fails.

thank you again

lemseffert,
repeating the same post again and again AND not following the suggested solutions will not get you too far.
Go through the entire thread, try to understand and follow the posted suggestions.
In any future postings, please follow the forum's rules and use the code tags when posting.

Good luck.

---------- Post updated at 06:26 PM ---------- Previous update was at 06:26 PM ----------

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags

```text
 and 
```

by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums