DaemonForums  

Go Back   DaemonForums > FreeBSD > FreeBSD General

FreeBSD General Other questions regarding FreeBSD which do not fit in any of the categories below.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 29th June 2008
godfrank godfrank is offline
Port Guard
 
Join Date: Jun 2008
Posts: 14
Default [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.
Reply With Quote
  #2   (View Single Post)  
Old 29th June 2008
cajunman4life cajunman4life is offline
Real Name: Aaron Graves
Package Pilot
 
Join Date: May 2008
Location: Coolidge, Arizona
Posts: 203
Default

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!
Reply With Quote
  #3   (View Single Post)  
Old 29th June 2008
godfrank godfrank is offline
Port Guard
 
Join Date: Jun 2008
Posts: 14
Default

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
Reply With Quote
  #4   (View Single Post)  
Old 29th June 2008
lvlamb's Avatar
lvlamb lvlamb is offline
Real Name: Louis V. Lambrecht
Spam Deminer
 
Join Date: May 2008
Location: .be
Posts: 221
Default

Rem: cron runs effectively on a 24/7 machine.
If you reboot frequently you should install sysutils/anacron
__________________
da more I know I know I know nuttin'
Reply With Quote
  #5   (View Single Post)  
Old 29th June 2008
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 4,125
Default

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
Reply With Quote
  #6   (View Single Post)  
Old 29th June 2008
godfrank godfrank is offline
Port Guard
 
Join Date: Jun 2008
Posts: 14
Default

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
Reply With Quote
  #7   (View Single Post)  
Old 29th June 2008
cajunman4life cajunman4life is offline
Real Name: Aaron Graves
Package Pilot
 
Join Date: May 2008
Location: Coolidge, Arizona
Posts: 203
Default

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!
Reply With Quote
  #8   (View Single Post)  
Old 29th June 2008
godfrank godfrank is offline
Port Guard
 
Join Date: Jun 2008
Posts: 14
Default

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.
Reply With Quote
  #9   (View Single Post)  
Old 29th June 2008
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 4,125
Default

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
Reply With Quote
Old 30th June 2008
godfrank godfrank is offline
Port Guard
 
Join Date: Jun 2008
Posts: 14
Default

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!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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


All times are GMT. The time now is 04:08 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick