Linux - NewbieThis forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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
The usual answer to such questions here is: Post what you've written, and where you're having a problem, and we'll be glad to help.
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.
for dev in *; do
somecommand <options> $dev
otherstuff
done
Here, "somecommand" wants a filename as its last argument. That is supplied by the value of the variable "dev". The way it is written, It would have to be run in the directory where the files are.
the above is for BASH, but I would expect ksh to be similar
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
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.