Skip to main content

Thread: Script won't run properly in cron


i'm don't understand why script runs flawlessly command line runs incompletely cron.

script supposed download html files web host , check see whether contain line. if don't contain line, moved folder line added. finally, edited files uploaded host.

here's script:

code:
#!/bin/bash -x    home_dir="/home/james/desktop/upload_apenterprisesllc"  doctype='<!doctype html public "-//w3c//dtd html 4.01 transitional//en">'  loose=' "http://www.w3.org/tr/html4/loose.dtd">'    failure_test () {    	if [ $? -ne 0 ];    		failure_alert "$1" "$2"    		exit 1    	fi    }      failure_alert () {    	echo "$1" | mutt -s "$2" ***********@verizon.net    }      lftp -u *********@aol.com,goforbroke ftp.intuitwebsites.com <<eod  set net:timeout 50  cd apenterprises || quit 1  mget -c -o $home_dir/ *html || quit 1  quit 0  eod    failure_test "couldn't download html files" "$0 error"    sleep 5    in $home_dir/*html;    	head $i | grep http://www.w3.org/tr/html4/loose.dtd &>/dev/null || mv $i "$home_dir/to_be_uploaded/"      done    if ls /home/james/desktop/upload_apenterprisesllc/to_be_uploaded/*html &>/dev/null;    	for j in "${home_dir}/to_be_uploaded/*html";    		awk -v doctype="$doctype" -v loose="$loose" '/doctype/{sub(/>/,loose)}{print}' $j \  		> ${home_dir}/to_be_uploaded/temp && rm $j && mv ${home_dir}/to_be_uploaded/temp ${home_dir}/to_be_uploaded/`basename "$j"` \  		|| failure_alert "could not edit html files" "$0 failure"       	done    	lftp -u *********@aol.com,goforbroke ftp.intuitwebsites.com <<eod  set net:timeout 50  mput -c -o /apenterprises ${home_dir}/to_be_uploaded/*html || quit 1  quit 0  eod    	failure_test "couldn't upload html files" "$0 error"    	rm ${home_dir}/*html    	failure_test "couldn't delete html files" "$0 error"    	rm ${home_dir}/to_be_uploaded/*html    	failure_test "couldn't delete html files" "$0 error"    	exit 0    else      rm ${home_dir}/*html      failure_test "couldn't delete html files" "$0 error"    	exit 0    fi
here's error output when script run in cron:
awk: cmd. line:1: fatal: cannot open file `/home/james/desktop/upload_apenterprisesllc/to_be_uploaded/*html' reading (no such file or directory)
ls: cannot access /home/james/desktop/upload_apenterprisesllc/to_be_uploaded/*html: no such file or directory
mput: /home/james/desktop/upload_apenterprisesllc/to_be_uploaded/*html: no files found
the problem seems cron doesn't recognize flow control. if there no html files in "to_be_uploaded" file, it's supposed skip awk-ing , uploading server section. doesn't reason , tries edit , upload files don't exist.

here's crontab:
0 * * * * /home/james/bin/upload_apenterprisesllc.bs 2>/home/james/failure.txt
any idea ? i'm stumped.

i figured out.
cron has own environmental variables, of different bash terminal's.
shell, cron uses /bin/sh while terminal uses /bin/bash.
also, cron's path variable may different bash terminal's.

added crontab
code:
shell=/bin/bash path=/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
doing seems have solved problem.


Forum The Ubuntu Forum Community Ubuntu Official Flavours Support General Help [SOLVED] Script won't run properly in cron


Ubuntu

Comments

Popular posts from this blog

Falang and too many redirects - Joomla! Forum - community, help and support

Infinite loop detected in JErrorInfinite loop detected in JError - Joomla! Forum - community, help and support

logged out from joomla! - Joomla! Forum - community, help and support