I have a script that checks IPs for ping reply then tries to run an snmpwalk on them. I am trying to schedule the script to run weekly in cron. When I run the script in the shell, it runs perfectly. When I execute the cron in webmin, it skips the second do/done set.
The script does a ping of IPs .21 through .30 and writes them to the 'hostip' file. It then runs each line of that file through the snmpwalk command.
#!/bin/bash
#USAGE: âscriptname 10.1.1â³
set +x
for i in {21..30};
do fping -t300 -a $1.$i >> hostip
done
set -x
cat hostip | while read line;
do
echo snmpwalk -v 2c -c public "$line" iso.3.6.1.2.1.17.4.3.1;
snmpwalk -v 2c -c public "$line" iso.3.6.1.2.1.17.4.3.1;
done
wait
rm -Rf hostip
When I run in the interactive shell (SSH) the hostfile is created and the snmpwalks are performed. However, when I click Run Now on the root cron in Webmin, I see:
+ set +x
+ cat hostip
+ read line
+ wait
+ rm -Rf hostip
It does not return the snmpwalk commands. How do I get the script to run in cron the same as it runs in inveractive shell? I have tried researching online but cannot find cases where echo, or the while read line causes problems. The script is executable
echo -n '' >hostip
just to make sure the file is empty when you start?set -x
above the for loop. I'd suspect the file is empty.