Thread: Bash script behaving differently in crontab vs manually run
greetings.
have script purges files folder , record (log file) of files purged.
wrote following snippet , works when executing command line:
when run command line, log file looks (shows each file deleted individually):code:logfile="/path/to/logfiles/purge-folder.log" echo "`date +%y-%m-%d_%h:%m:%s` - script started." >> ${logfile} file in "/path/to/folder/*.txt" echo " - info: deleting ${file}" >> ${logfile} rm ${file} done echo "`date +%y-%m-%d_%h:%m:%s` - script completed." >> ${logfile}
when run crontab, log file looks (no matter how many files deleted):code:2013-03-01_10:43:35 - script started. - info: deleting /path/to/folder/20130227.txt - info: deleting /path/to/folder/20130228.txt - info: deleting /path/to/folder/20130301.txt 2013-03-01_10:43:35 - script completed.
this how root crontab looks:code:2013-03-02_10:00:01 - script started. - info: deleting /path/to/folder/*.txt 2013-03-02_10:00:01 - script completed.
any idea on how script behave in crontab @ command-line?code:shell=/bin/sh path=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 0 10 * * * /path/to/scripts/purge-folder.sh > /dev/null 2>&1
thanks,
lhammonds
remove excessive quoting
code:logfile="/path/to/logfiles/purge-folder.log" echo "`date +%y-%m-%d_%h:%m:%s` - script started." >> ${logfile} file in /path/to/folder/*.txt # excessive double quotes removed line echo " - info: deleting ${file}" >> ${logfile} rm ${file} done echo "`date +%y-%m-%d_%h:%m:%s` - script completed." >> ${logfile}
Forum The Ubuntu Forum Community Ubuntu Specialised Support Ubuntu Servers, Cloud and Juju Server Platforms Bash script behaving differently in crontab vs manually run
Ubuntu
Comments
Post a Comment