shell scripting
hello all,
i'm new to this group, so please be patient with me 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 !!!(if its correct) for each device to see if its running snmpget, I want to create a file for all the the devices that are running snmpget and ofcourse will return zero. if possible been able to see if someone try to hack mmy devices,will show a number for example drop### =2 (means someone try to hack it twice) I am new to scripting so any help would be appreciated. This is for a solaris box, and KSH. Thanks |
Quote:
There are thousands of shell script tutorials on Google that can help you. Also, this may be more suited to the Solaris forum here, since it's not really Linux related. |
More ksh docs than you can poke a stick at
http://kornshell.com/ |
A partial answer:
Code:
for dev in *; do the above is for BASH, but I would expect ksh to be similar |
thanks pixellany
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 |
hello again
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. |
What does var=` <some command> ` do? It doesn't put the exit status of <some command> in var.
See the Advanced Bash-Scripting Guide for "command substitution" explanation and examples and then again here for "exit status" explanation and examples. |
Your 1st line is hopeless; you've got 2 single quotes and a double quote. You prob want backquotes at the start and end, and single quotes for the awk cmd.
Also, you have double pipe symbols after 'hosts'. This is an 'or' operator. You prob meant 1 pipe. You are using the wrong comparator in the if statement: http://tldp.org/LDP/abs/html/comparison-ops.html Have a deep read of that doc. Also, consider using $(cmd) instead of `cmd` its easier to read/debug if you have other types of quote marks involved. |
thank you chrism01
i fixed all of those comments but actually what i'm looking for is to be able to check for community name for all my devices , if its correct return 0 if not return 1. Thanks again |
So post your corrected script and we'll take it from there. It's easier to read if you put it in code tags (that's a link to instructions or you may prefer to use "Advanced Edit" mode which has a # button for code tags).
|
Thank you catkin
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 |
You may(!) have 'fixed all those comments' somewhere, but the above code does not show it. It's almost identical to your first code post.
Post the 'fixed' code in code tags as requested by Catkin, and we'll go from there. |
All times are GMT -5. The time now is 02:54 PM. |