crontab中的脚本没有运行

时间:2014-05-07 23:40:00

标签: cron debian

我有一个问题,crontab根本没有运行我的脚本。我已将脚本简化为单行,但仍然无法运行:

$ cat /etc/crontab
# /etc/crontab: system-wide crontab                                             
# Unlike any other crontab you don't have to run the `crontab'                  
# command to install the new version when you edit this file                    
# and files in /etc/cron.d. These files also have username fields,              
# that none of the other crontabs do.                                           

SHELL=/bin/sh                                                                   
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin               

# m h dom mon dow user  command                                                 
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly             
25 6    * * *   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 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
*/1 * * * * root /usr/share/test/script.sh                         
# don't forget the newline at the end (https://askubuntu.com/a/23337/12057):     


$ cat /usr/share/test/script.sh
#!/bin/bash                                                                     
echo "got here" > /tmp/test.txt

$ ls -l /usr/share/test/script.sh
-rwxr-xr-x 1 root root 951 May  8 08:59 /usr/share/test/script.sh

$ uname -a
Linux mypcname 3.2.0-4-amd64 #1 SMP Debian 3.2.51-1 x86_64 GNU/Linux

$ ps aux | grep cron
root      1111  0.0  0.0  22222  3333 ?        Ss   08:27   0:00 /usr/sbin/cron
me        4444  0.0  0.0   5555   666 pts/0    S+   09:06   0:00 grep --color=auto cron

正如您所看到的,crontab应该每分钟运行一次script.sh并写入文件/tmp/test.txt,但此文件永远不会出现。我一直在阅读these possible reasons for cron not running,但到目前为止,它们都不适用。我以为一双新鲜的眼睛可能会散发一些光芒。

2 个答案:

答案 0 :(得分:0)

每分钟都是

  

* * * * *

  

* / 1 * * * *

相关问题:Using crontab to execute script every minute and another every 24 hours

答案 1 :(得分:0)

/var/log/syslog提供了答案的线索:

May  8 08:50:01 mypcname /usr/sbin/cron[2222]: (*system*) WRONG FILE OWNER (/etc/crontab)
May  8 08:51:01 mypcname /usr/sbin/cron[2222]: (*system*) WRONG FILE OWNER (/etc/crontab)

$ ls -l /etc/crontab
lrwxrwxrwx 1 root root 24 Oct 12 2013 /etc/crontab -> /home/me/.crontab

$ ls -l ~/.crontab
-rw-r--r-- 1 root root 24 Oct 12 2013 /home/me/.crontab

我记得我在安装debian操作系统时这样做,因为我家里的所有内容都是从subversion存储库中检出的。我解决了这个问题:

$ sudo cp ~/.crontab /etc/crontab

现在一切正常:)