Need help creating a script

I need to automate the following process:

I have a list of ip address for printers in a file called iplist.txt, I need to take that list and run the command

snmpget -v 1 -c public ip address sysName.0

for each ip address to see if the printer is running snmp, I want to the create a file for any ip address that is not running snmp.

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

Thanks

This should get you started:

#!/bin/ksh
# assuming snmpget returns non-zero when printer not running snmp
echo "These ip addresses are not running snmp on " `date` > nosnmp.log
while read ipaddr
do                                                                                                                  
    snmpget -v 1 -c public $ipaddr sysName.0 
    if [ $? -ne 0 ]; then 
        echo "$ipaddr" >> nosnmp.log          
    fi    
done < iplist.txt                                              

The response from the request is

Timeout: No Response from ip address

So would I just change the code where is say

 [ $? -ne 0 ] 

to say

 [ $? -ne Timeout: No Response from ip address ] 

?

[ $? -ne 0 ]

should take care of that.

jim's code as written is correct ...

but instead of just snmpget why don't you do a ping with a timeout first so you don't have to wait forever for each ip address ... i've modified jim's code below using a 5 second timeout on ping and taking out the "Timeout:" error ...

#!/bin/ksh
# assuming snmpget returns non-zero when printer not running snmp
echo "These ip addresses are not running snmp on " `date` > nosnmp.log
while read ipaddr
do
    ping $ipaddr 5 > /dev/null 2>&1
    if [ $? -eq 0 ]
    then   
          snmpget -v 1 -c public $ipaddr sysName.0 2> /dev/null
          if [ $? -ne 0 ]; 
          then 
                echo "$ipaddr" >> nosnmp.log
          fi
     else
          echo "$ipaddr" >> nosnmp.log
     fi 
done < iplist.txt

or else you can simply do ... since an unpingable networked printer is technically off the network functionwise ... (assuming a 2 second ping timeout) ...

#! /bin/ksh
echo "These ip addresses are unpingable as of [ `date` ]\n" > noping.log
for ipaddr in `< iplist.txt`
do
     ping $ipaddr 2 2> /dev/null
     if [ $? -ne 0 ]
     then
           echo "$ipaddr" >> noping.log
     fi
done

exit 0