首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么我每周的anacron工作没有执行?

为什么我每周的anacron工作没有执行?
EN

Ask Ubuntu用户
提问于 2013-10-14 06:47:47
回答 3查看 27.9K关注 0票数 8

我想用anacron在Ubuntu13.04上每周做一次工作。

这是我的/etc/crontab:

代码语言:javascript
复制
# /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    * * 5   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 )
#

这是我的/etc/anacrontab:

代码语言:javascript
复制
# /etc/anacrontab: configuration file for anacron

# See anacron(8) and anacrontab(5) for details.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
HOME=/root
LOGNAME=root

# These replace cron's entries
1   5   cron.daily  run-parts --report /etc/cron.daily
7   10  cron.weekly run-parts --report /etc/cron.weekly
@monthly    15  cron.monthly    run-parts --report /etc/cron.monthly

这是我的/etc/cron.Week/0 0anacron:

代码语言:javascript
复制
#!/bin/sh
#
# anacron's cron script
#
# This script updates anacron time stamps. It is called through run-parts
# either by anacron itself or by cron.
#
# The script is called "0anacron" to assure that it will be executed
# _before_ all other scripts.

test -x /usr/sbin/anacron || exit 0
anacron -u cron.weekly

最后,这里是我输入的脚本/etc/cron.Week/:

代码语言:javascript
复制
#!/bin/sh
curlftpfs -o allow_other,skip_pasv_ip mauro-casa.no-ip.org:21001/Volume_1/Foto/Marta/ /home/mauro/Pubblici/Marta_NAS/
sleep 5
rsync -rlt --update --ignore-existing --size-only --exclude=.picasaoriginals/* --exclude=.picasaoriginals --exclude=.directory --exclude=.dropbox --exclude=picasa.ini --temp-dir=/home/mauro/.rsync-temp/ /home/mauro/Dropbox/Marta/ /home/mauro/Pubblici/Marta_NAS/
umount -l /home/mauro/Pubblici/Marta_NAS/

这个脚本显然是chmoded +x,如果手动执行它(使用sudo),它工作得很好。

编辑#1

按照要求,这里的输出

代码语言:javascript
复制
cat /var/log/cron.log | grep "Oct 13"

Oct 13 08:29:05 mauro-alienware anacron[1315]: Anacron 2.3 started on 2013-10-13
Oct 13 08:29:05 mauro-alienware cron[1266]: (CRON) INFO (pidfile fd = 3)
Oct 13 08:29:05 mauro-alienware cron[1403]: (CRON) STARTUP (fork ok)
Oct 13 08:29:05 mauro-alienware cron[1403]: (CRON) INFO (Running @reboot jobs)
Oct 13 08:29:06 mauro-alienware anacron[1315]: Will run job `cron.daily' in 5 min.
Oct 13 08:29:06 mauro-alienware anacron[1315]: Jobs will be executed sequentially
Oct 13 08:34:05 mauro-alienware anacron[1315]: Job `cron.daily' started
Oct 13 08:34:05 mauro-alienware anacron[1651]: Updated timestamp for job `cron.daily' to 2013-10-13

似乎没有显示cron.weekly的日志。

相反,下面是cat /var/log/cron.log.1 | grep "Oct 11"输出的摘录:

代码语言:javascript
复制
Oct 11 06:47:01 mauro-alienware CRON[12553]: (root) CMD (test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly ))
Oct 11 06:59:11 mauro-alienware anacron[5125]: Anacron 2.3 started on 2013-10-11
Oct 11 06:59:11 mauro-alienware anacron[5125]: Normal exit (0 jobs run)
Oct 11 07:45:54 mauro-alienware anacron[5444]: Anacron 2.3 started on 2013-10-11
Oct 11 07:45:54 mauro-alienware anacron[5444]: Normal exit (0 jobs run)
Oct 11 07:46:39 mauro-alienware CRON[9156]: (root) CMD (start -q anacron || :)
Oct 11 07:46:39 mauro-alienware anacron[9159]: Anacron 2.3 started on 2013-10-11
Oct 11 07:46:39 mauro-alienware anacron[9159]: Normal exit (0 jobs run)
Oct 11 08:46:31 mauro-alienware cron[1249]: (CRON) INFO (pidfile fd = 3)
Oct 11 08:46:31 mauro-alienware cron[1308]: (CRON) STARTUP (fork ok)
Oct 11 08:46:31 mauro-alienware cron[1308]: (CRON) INFO (Running @reboot jobs)
Oct 11 08:46:31 mauro-alienware anacron[1303]: Anacron 2.3 started on 2013-10-11
Oct 11 08:46:31 mauro-alienware anacron[1303]: Normal exit (0 jobs run)
Oct 11 08:46:35 mauro-alienware anacron[1839]: Anacron 2.3 started on 2013-10-11
Oct 11 08:46:35 mauro-alienware anacron[1839]: Normal exit (0 jobs run)
Oct 11 08:46:37 mauro-alienware anacron[4700]: Anacron 2.3 started on 2013-10-11
Oct 11 08:46:37 mauro-alienware anacron[4700]: Normal exit (0 jobs run)
EN

回答 3

Ask Ubuntu用户

发布于 2014-12-08 10:30:03

您没有发布要运行的脚本的实际名称,但是它很可能包含一个点('.'),就像它以‘..sh’结尾一样。

run -部件将不运行除了字母、数字字符或连字符以外的其他任何内容的脚本。去掉点,你就没事了。

票数 18
EN

Ask Ubuntu用户

发布于 2013-10-14 09:38:08

anacron什么时候运行

通常,anacron不作为守护进程运行。在基于Debian的系统上,它与/etc/cron.d/anacron的经典cron一起运行。它也在系统启动后开始,从睡眠中恢复并改变电源管理状态。

您可以检查最后一次使用sudo cat /var/spool/anacron/cron.weekly运行anacron作业的日期。

票数 9
EN

Ask Ubuntu用户

发布于 2014-10-16 11:24:02

代码语言:javascript
复制
cat /etc/cron.d/anacron

将告诉您anachron将运行的时间和时间,例如:

代码语言:javascript
复制
# /etc/cron.d/anacron: crontab entries for the anacron package

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

30 7    * * *   root    start -q anacron || :

向你展示它每天早上7:30运行,但每周只运行一次。它检查写入的日期。

代码语言:javascript
复制
sudo cat /var/spool/anacron/cron.weekly

(如果日期较旧,它将启动并更新该文件中的日期)

票数 1
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/358813

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档