Thread: weird script output when run with cron
hi all,
planned on adding quick script cron email me if backup didnt run - short term until can amend perl script handle errors.
might simple mistake cannot see it! can run below command manually when run via cron $lastbkup variable displays 'jan' instead of date in format '20110111' -- ideas why?
annoying me!
#!/bin/bash
#quick script email if backup doesnt run
bkup_dir='/share/backups/';
lastbkup=$(/bin/ls -ltr $bkup_dir | /usr/bin/tail -1 | /usr/bin/awk '{print $6}' | /bin/sed 's/\-//g');
mail='blahblahblah@gmail.com';
d=$(/bin/date \+\%y\%m\%d);
if [ ${lastbkup} -ne ${d} ]; then
echo "backup failed, date:${d} , last_backup: ${lastbkup}" | mail -s "backup failed" ${mail} ;
fi
code:#!/bin/bash #quick script email if backup doesnt run bkup_dir='/share/backups/'; lastbkup=$(/bin/ls -ltr --time-style="+%y%m%d" $bkup_dir | /usr/bin/tail -1 | /usr/bin/awk '{print $6}' | /bin/sed 's/\-//g'); mail='blahblahblah@gmail.com'; d=$(/bin/date \+\%y\%m\%d); if [ ${lastbkup} -ne ${d} ]; echo "backup failed, date:${d} , last_backup: ${lastbkup}" | mail -s "backup failed" ${mail} ; fi
Forum The Ubuntu Forum Community Ubuntu Official Flavours Support General Help [SOLVED] weird script output when run with cron
Ubuntu
Comments
Post a Comment