简体   繁体   中英

cron job not started daily

I have a script in /etc/cron.daily/backup.sh file is allowed to execute and run but do not start happening, I read the manual and used the search but not mastered decision.

ls -l /etc/cron.daily/
total 52
-rwxr-xr-x 1 root root 8686 2009-04-17 10:27 apt
-rwxr-xr-x 1 root root 314 2009-02-10 19:45 aptitude
-rwxr-xr-x 1 root root 103 2011-05-22 19:08 backup.sh
-rwxr-xr-x 1 root root 502 2008-11-05 03:43 bsdmainutils
-rwxr-xr-x 1 root root 89 2009-01-27 00:55 logrotate
-rwxr-xr-x 1 root root 954 2009-03-19 16:17 man-db
-rwxr-xr-x 1 root root 646 2008-11-05 03:37 mlocate

The cron job filename can't have a period in it on certain ubuntus. See this . Particularly, this quote within:

Although the directories contain periods in their names, run-parts will not accept a file name containing a period and will fail silently when encountering them

Properly, this is a problem with run-parts, which the ubuntu cron runs, and not with cron itself. Still, it's what bit me.

pls check:

1a) is the script executable and has correct owner/group settings?

1b) does it start with the correct #! line? and do you specify the full path to the shell you're using, eg #!/bin/bash ?

2) does the script generate an error while being executed? eg can you write to a log file from it, and do you see the log messages?

also: check in the email inbox of the user who owns the crontab -- errors are emailed to the user / eg root

what does the output of ls -l /etc/cron.daily/ look like? can you post that?


NOTE:

you can always create a crontab entry for this yourself, outside of those cron.xxx directory structure ;-)

See: man 5 crontab

 10 1 * * * /somewhere/backup.sh >> /somewhere/backup.log 2>&1

this has the advantage that you get to pick the exact time when it runs (eg 1:10am here), and you can redirect STRERR and STDOUT to append to a log file for that particular script

For testing purposes you could run it ever 10 minutes, like this:

 0,10,20,30,40,50 * * * * /somewhere/backup.sh >> /somewhere/backup.log 2>&1

do touch /somewhere/backup.log to make sure it exists

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM