Issue with cron

I'm using CentOS 5 and I need to get cron working and I'm not sure what the problem is. As a test I've done the following:

1) In /etc/cron.d I've created a file called date with the following contents

2) */1 * * * * root date >> /root/thedate

3) This works perfectly. It sends the date every minute to /root/thedate with no problem

Then when I tried the following, it would not work:

1) In /etc/cron.d I changed the file named "date" to contain the following:

2) */1 * * * * root /root/date.sh

3) The contents of /root/date.sh is the following:

!/bin/sh

date >> /root/thedate

4) I chmoded /root/date.sh to 700 and was able to run it by executing ./date.sh

5) However, crond would not run this cron job and I am confused

Any help is appreciated.

7 Replies

Any information in /var/log/cron ?

These are the lines that are repeated over and over in /var/log/cron:

Aug 18 22:11:01 myhost crond[14990]: (root) CMD ('/root/date.sh')

Aug 18 22:12:01 myhost crond[14993]: (root) CMD ('/root/date.sh')

Aug 18 22:13:01 myhost crond[15000]: (root) CMD ('/root/date.sh')

Then cron is trying to run the command. Did you upload the file from a Windows PC? Is it in DOS mode? Try running dos2unix on /root/date.sh just in case

Sorry the single quotes are not suppose to be there. It should be:

Aug 18 22:11:01 myhost crond[14990]: (root) CMD (/root/date.sh)

Aug 18 22:12:01 myhost crond[14993]: (root) CMD (/root/date.sh)

Aug 18 22:13:01 myhost crond[15000]: (root) CMD (/root/date.sh)

I wrote the cron job in nano through SSH.

Well, cron is definitely trying to run the job. So

1) make sure it's in unix format (dos2unix)

2) fully qualify every path (/bin/date and not just date)

3) Check to see if anything is appearing in root mail (cron failures are typically emailed)

Did all of those. Still not working :(

Works for me:

/etc/cron.d$ cat date
* * * * * root /root/date.sh
/etc/cron.d$ ls -l /root/*date*
-rwx------ 1 root root 32 Aug 20 12:52 /root/date.sh*
-rw-r--r-- 1 root root 87 Aug 20 12:56 /root/thedate
/etc/cron.d$ sudo cat /root/date.sh
#!/bin/sh
date >> /root/thedate
/etc/cron.d$ cat /root/thedate
Wed Aug 20 12:52:35 CDT 2008
Wed Aug 20 12:55:01 CDT 2008
Wed Aug 20 12:56:01 CDT 2008

All on my linode running Debian etch. The first line in "thedate" is from a manual run; the next two are from cron updates. (BTW, '*/1 * * * ' is the same as ' * * * *').

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct