|
FreeBSD General Other questions regarding FreeBSD which do not fit in any of the categories below. |
|
Thread Tools | Display Modes |
|
|||
[SOLVED] Cronjob script does not run in cron
Hello mateys!
I have a /root/backups.sh script which should be run by a cronjob. What it does is tar many directories, encrypt them with GnuPG and then move the gpg file to a usb stick that was mounted by that very same script. It works flawlessly if I run the script manually from root. However, it does not seem to be run when I put it in a cronjob although I have an entry in /var/log/cron saying it was run. Also, I don't have any entry in /var/log/messages about the mounting of the usb stick. I put some debug lines (as in echo "start" > /root/backups.log) and they do not even get executed! Is there something I should know? Thanks folks and thank you for building a new and better forum! ;-) Last edited by godfrank; 30th June 2008 at 12:41 AM. |
|
|||
It could be helpful to post your script here
Be sure to sanitize anything that you might not want to be public (passwords, etc) but try not to remove too much of the script so that we might be able to hunt down the problem for you.
__________________
I just saved a bunch of money on my car insurance by fleeing the scene of the accident! |
|
|||
Here it is!
Thanks! Code:
#!/bin/sh echo "START" > /root/backups.log mount -t msdosfs /dev/da0s1 /mnt/usb-storage echo "AFTER MOUNT" >> /root/backups.log # Leave now if we're not on the backups usb stick if [ ! -e /mnt/usb-storage/dummyfile ]; then echp "Error. Wrong USB stick plugged in." >> /root/backups.log echo "Error. Wrong USB stick plugged in." umount /mnt/usb-storage exit 1 fi rm -f /mnt/usb-storage/*.gpg echo "AFTER REMOVING ALL GPG FILES ON USB STORAGE" >> /root/backups.log # Current date; used for filename FILENAME=/home/frank/`date +'%Y-%m-%d'`-frank.tar.gz FILENAMEGPG=$FILENAME.gpg echo "FILENAME = $FILENAME" >> /root/backups.log echo "FILENAMEGPG = $FILENAMEGPG" >> /root/backups.log echo "BEFORE TAR" >> /root/backups.log tar -cvzpf $FILENAME /home/frank/.mozilla/firefox/ echo "AFTER TAR" >> /root/backups.log gpg -e -r email@domain.com $FILENAME echo "AFTER GPG" >> /root/backups.log rm -f $FILENAME echo "REMOVED TAR FILE" >> /root/backups.log mv $FILENAMEGPG /mnt/usb-storage/ echo "AFTER MOVED GPG FILE TO USB STORAGE" >> /root/backups.log umount /mnt/usb-storage echo "AFTER UMOUNT USB STORAGE" >> /root/backups.log |
|
|||
The only thing you should know is that the PATH in a CRON environment is very limited compared to the PATH in the cron environment.
You either explicitly set and export the value of PATH in your cron script, or use fully qualified names for the utilities you use. For example: /bin/tar instead of tar.
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump |
|
|||
Hello folks,
thanks for the answers. My machine is always up. For my tests, I created cron jobs one minute after the current time and the job was executed every time according to /var/log/cron. I have modified the first echo so it now looks like this: /bin/echo "START" > /root/backups.log However, after the job was ran (according to /var/log/cron), the /root/backups.log does not contain that entry. It really looks like the script was not executed at all. I really don't understand what's happening |
|
|||
Hmm... what does your crontab entry look like? Also, this may seem silly, but... is the "x" set for execute? "-rwxr-xr-x" for example?
__________________
I just saved a bunch of money on my car insurance by fleeing the scene of the accident! |
|
|||
Hello,
my crontab entry (for tests) looks like this: 43 17 * * * root /root/backups.sh At first I tried without setting the username under which it should be run. Yep, the permissions are set to a+rx. |
|
|||
Are you aware of http://www.freebsd.org/doc/en_US.ISO...ning-cron.html, which explains that FreeBSD has two different crontabs? The first is the system or root's crontabs, the second are the user crontabs. They have a slightly different format
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump |
|
|||
I guess it was a case of RTFM!
I also added the PATH in my crontab and added /usr/local/bin to the PATH given in the handbook in order to resolve GnuPG correctly. Thank you! |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Cron won't execute a perl script | ivanatora | FreeBSD General | 4 | 17th August 2008 07:53 AM |
cron newsyslog message | starbuck | FreeBSD General | 2 | 6th August 2008 07:33 PM |
Cron running but not working | stukov | Other BSD and UNIX/UNIX-like | 26 | 24th July 2008 01:17 PM |
Please help me automate getmail with cron | cssgalactic | FreeBSD General | 2 | 9th July 2008 10:13 PM |
Using sendmail in a cron job | erehwon | OpenBSD General | 6 | 15th May 2008 09:03 PM |