Skip to main content

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:

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 command line, log file looks (shows each file deleted individually):

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.
when run crontab, log file looks (no matter how many files deleted):

code:
2013-03-02_10:00:01 - script started.  - info: deleting /path/to/folder/*.txt 2013-03-02_10:00:01 - script completed.
this how root crontab looks:

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
any idea on how script behave in crontab @ command-line?

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

Popular posts from this blog

Some mp4 files not displaying correctly (CS6)

Thread: Samba is not authenticating with LDAP