Script in /etc/cron.daily (Hourly,Weekly) won't Run or Exec

人氣點閱:2554
發表人
Script in /etc/cron.daily (Hourly,Weekly) won't Run or Exec 2012-12-03 11:35
/ / /

Script in /etc/cron.daily (Hourly,Weekly) won't Run or Execute



Symptoms:
=> Script won't Run or Execute in these Ubuntu Linux Folders
/etc/cron.hourly
/etc/cron.daily
/etc/cron.weekly
/etc/cron.monthly

Possible Check-Points

1. Make sure NO /usr/sbin/anacron existed



Otherwise, we will run "anacron" first before running "run-parts"
代碼:

$ ls -l /usr/sbin/anacron
ls: cannot access /usr/sbin/anacron: No such file or directory

$ grep "*" /etc/crontab
17 *    * * *  root    cd / && run-parts --report /etc/cron.hourly
25 5    * * *  root     test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7  root     test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 7    1 * *  root     test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
                        ^^^^^^^^^^^^^^^^^^^^^^^^^


2. Rename/Remove "dot" and ".sh" from your script filename



Some run-parts parameters has filename name space constraints:

e.g.
代碼:

$ cd /etc/cron.daily/
$ sudo mv daily_backup_userfolder.sh dailybackupuserfolder



3. Make your script executeable



Of course, make them with +x permission.

代碼:

$ cd /etc/cron.daily/
$ sudo chmod 755 <YOUR SCRIPT>



4. Specify proper shell directives (e.g. #!/bin/sh or #!/bin/bash)



Finally, check if there is shell directives at first line.

代碼:

$ cd /etc/cron.weekly
$ sudo vi <YOUR SCRIPT>
  # (... Add a #!/bin/sh at first line ...)