Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

wouldn't be posting here if I hadn't tried everything I could find on the interwebs...would appreciate any guidance from a seasoned sysadmin.

Here is my problem: cron jobs in /etc/cron.daily, /etc/cron.hourly etc. are running fine on my Slicehost Ubuntu server -- their execution is being logged to both /var/log/syslog and /var/log/cron.log

I've created two test cron jobs, one as root and one as an admin user, through crontab that are supposed to run every minute. Here is the output of crontab -l run as root

$ crontab -l
* * * * * /bin/date > /tmp/unicorns
$ crontab -u neil0 -l
* * * * * /home/neil0/crontab/unicorn.sh >> /home/neil0/logs/crontab.log >&1

EDIT 1: I didn't copy this exactly...there was no newline in the output and that was the source of the problem

here are the contents of unicorn.sh

#!/bin/sh
echo 'UNICORNS'

but neither /home/neil0/logs/crontab.log nor /tmp/unicorns is being updated, and there is no record of these jobs being run in /var/log/syslog or /var/log/cron.log!

before you ask, it does appear that cron is running --

$ ps aux | grep cron
root      1588  0.0  0.1  18616   980 ?        Ss   12:31   0:00 /usr/sbin/cron
root      1798  0.0  0.1   3944   604 pts/0    R+   13:01   0:00 grep cron

in case you were wondering 'unicorn' is my replacement frustration word for 'F***' ever since a certain debugging snafu with a live website sooooo as you can see i'm pretty much at my wits end here. any help would be greatly appreciated.

share|improve this question
    
Have you creating these as a crontab fragment in /etc/cron.d/? –  Zoredache Oct 7 '09 at 17:19
    
not sure what that means exactly...I created them using crontab on a file, like the file was called unicorn.cron and was just one line with * * * * * /bin/date > /tmp/unicorns and then i did $ crontab unicorn.cron –  Neil Sarkar Oct 7 '09 at 17:22
    
i should mention that that command created files in /var/spool/cron/crontabs/ do i have to do something to get cron to pick those up? –  Neil Sarkar Oct 7 '09 at 17:26

1 Answer 1

up vote 4 down vote accepted

uh...huh. so as I'm guessing most of you already know, you need to end your crontab files with a newline. that was the whole issue. hope this helps someone else

share|improve this answer
    
Just curious how this happened in the first place. Were you editing the crontab files directly? Or were you editing them with 'crontab -e'? –  3dinfluence Oct 7 '09 at 19:23
    
Well I just created the file (for example unicorn.cron) manually in emacs, put in the line you see above, and then added it to cron with crontab unicorn.cron I had done it this way in the past and it worked but I guess I had always fortuitously put a newline in. I just took a look at crontab -e and I guess that is the standard accepted way to create a new cron job for a user? Will def use in the future –  Neil Sarkar Oct 7 '09 at 19:54
2  
Yes 'crontab -e' is the way to go. It will open the existing cron file in your the program you have set to your EDITOR environment variable and then install it when you're done. It also does some sanity checks before installing the new file so I would think that it would have added the necessary newline. So if you want it to use emacs you just need to set the appropriate env variable. –  3dinfluence Oct 7 '09 at 20:56
    
Hi @NeilSarkar, thanks a lot for sharing. May I ask how you can add a newline to crontab -e? I've been searching for a solution for the last 2 hours but no success. Naively putting newline character % at the end of the last command or below it does not work for me unfortunately –  fuzzybee Oct 23 '12 at 8:54
    
I have 2 commands in my crontab as follows btw: */5 * * * * ec2-automate-backup.sh -v "vol-myvolumeid" -k 3 * * * * * unicorn.sh >> /root/logs/crontab.log –  fuzzybee Oct 23 '12 at 8:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.