[SunHELP] cron script error

Jeff Howie sunhelp at sunhelp.org
Wed Feb 28 15:21:57 CST 2001


Cardinal Christopher wrote:
> 
> When I run a script from the command line as root, it works fine. When I run
> the script as a cron job for root, I get an error (I think I am missing
> something simple here.) The script and error are below:
> 
> ERRORS:
> /usr/netscape/smartfilter/get_lists[41]: -O:  not found
> /usr/netscape/smartfilter/get_lists[42]: -O:  not found
> 
> SCRIPT: I made bold the errors in the script when run from cron
> #!/usr/bin/ksh
> # SmartFilter Download Script
> # Generated by installation program
> 
> FTP_PROXY="http://gateway"
> SMART="/usr/netscape/smartfilter"
> LOG="$SMART/smart.log"
> WGET="$(whence wget)"
> DATE=`date`
> MAIL=/usr/ucb/mail

My First guess would be here. When a script is run via cron, it gets a much more
limited environment than a user login. For one thing, the /etc/profile probably
isn't being sourced. So your PATH would most likely not be the same.

Put an echo to check the values of all of these variables you've set, like:

echo "WGET: $WGET"

I'll bet that wget isn't found from in cron's path. Thus the error makes sense.
The command '$WGET -O' comes out as just '-O'.

> cd $SMART
> echo "$DATE" > $SMART/smart.log
> 
> #SmartFilter Download Script
> 
> if [ -f "wtcontrol.new" ];then
>   rm wtcontrol.new
> fi
> 
> if [ -f "wtcntldr.new" ];then
> 
> if [ -f "wtcntldr.new" ];then
>   rm wtcntldr.new
> fi
> 
> ## Following FTP script replaced by wget...
> #echo "Running ftp.."
> # Change "user" command below to specify a different account
> # and password, in the format "user [account] [password]"
> #echo "open
> #user s
> #cd /pub/NetscapeProxy/SOLARIS2
> #bin
> #get wtcontrol wtcontrol.new
> #get wtcntldr wtcntldr.new
> #close
> #quit
> #" | ftp -n
> 
> $WGET -O $SMART/wtcontrol.new -o $LOG -nH ftp://test:test@ftp.smartfilter
> .com/pub/NetscapeProxy/SOLARIS2/wtcontrol
> $WGET -O $SMART/wtcntldr.new -a $LOG -nH ftp://test:test@ftp.smartfilter.
> com/pub/NetscapeProxy/SOLARIS2/wtcntldr
> 
> if [ ! -f "wtcontrol.new" ];then
>         echo "Error: failed to download wtcontrol file, aborting..."
>         $MAIL -s"Smart Download-1 failed" test at test.test.com
>         exit 1
> fi
> 
> if [ ! -f "wtcntldr.new" ];then
>         echo "Error: failed to download wtcntldr file, aborting..."
>         $MAIL -s"Smart Download-2 failed" test at test.test.com
>         exit 1
> fi
> 
> echo "Checking control lists.."
> 
> r1=`./sfctlchk wtcontrol.new`
> r2=`./sfctlchk wtcntldr.new`
> 
> if [ ! $r1 = "OK" ];then
>  echo "Error: wtcontrol file appears to be corrupt"
>         $MAIL -s"Smart Download-3 failed" test at test.test.com
> fi
> 
> if [ ! $r2 = "OK" ];then
>         echo "Error: wtcntldr file appears to be corrupt"
>         $MAIL -s"Smart Download-4 failed" test at test.test.com
> fi
> 
> if [ $r1 = "OK" -a $r2 = "OK" ];then
>     echo "Installing new control lists, saving old lists as *.previous.."
>     mv wtcontrol wtcontrol.previous
>     mv wtcontrol.new wtcontrol
>     mv wtcntldr wtcntldr.previous
>     mv wtcntldr.new wtcntldr
>     echo "Setting permissions.."
>     chmod a+r wtcontrol
>     chmod a+r wtcntldr
> else
>         echo "Corrupt list(s), aborting..."
>         $MAIL -s"Smart Download-5 failed" test at test.test.com
>         exit
> fi
> echo "SmartFilter lists successfully downloaded."
> $MAIL -s"Smart Download succeeded" test at test.test.com
> exit
> # End of generated script



-- 
THKS :&) Jeff Howie



More information about the SunHELP mailing list