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.

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

Where exactly do you think the cwd (working directory) is? Are you sure your cron script has write access in that directory? Shouldn't you really be explicitly setting a working directory or giving a full path to the hostip file? Also wouldn't it be wise to start off you script with something like echo -n '' >hostip just to make sure the file is empty when you start?
– ZoredacheSep 27 '14 at 0:26

cwd is /opt/axxcheck, I defined this in the command of the cron (cd /opt/axxcheck && sh -x script.sh 192.168.0 >> output.log). The script is running as root, so I assumed that it would have write access to /opt/axxcheck. It would be wise to check that hostip is blank, thanks for that tip.
– kdawg4Sep 27 '14 at 1:06

Move set -x above the for loop. I'd suspect the file is empty.
– glenn jackmanSep 27 '14 at 1:10

I removed the rm -Rf hostip. When run in interactive shell, the file is created properly hence the snwmpwalk working. When cron runs the script, it creates the file but does not add any lines to the file.
– kdawg4Sep 27 '14 at 1:36