我的 crontab 中有一个 cron
45 18 * * * root /bkp_db.sh
但它不起作用。它没有被执行。我做错了什么?
在我的脚本中:
NOW=$(date +"%Y-%m-%d")
mysqldump -u root apps_db > bkp_apps/dump_app1_$NOW.sql
mysqldump -u root app_db2 > bkp_apps/dump_app2_$NOW.sql
zip -r bkp_apps/bkp_apps_$NOW.zip /var/www/myapps/public_html
答案1
您的个人 crontab 文件应该如下所示
45 18 * * * /bkp_db.sh
有多个 crontab 文件,每个文件的布局略有不同。通过编辑的个人 crontab 文件crontab -e
不包含用户名。
man crontab
说,
There is one file for each user's crontab under the
/var/spool/cron/crontabs directory. Users are not allowed to edit the
files under that directory directly to ensure that only users allowed by
the system to run periodic tasks can add them, and only syntactically cor‐
rect crontabs will be written there. This is enforced by having the
directory writable only by the crontab group and configuring crontab com‐
mand with the setgid bid set for that specific group.
但如果你读了,man cron
你也会读到,
Additionally, in Debian, cron reads the files in the /etc/cron.d direc‐
tory. cron treats the files in /etc/cron.d as in the same way as the
/etc/crontab file (they follow the special format of that file, i.e. they
include the user field). However, they are independent of /etc/crontab:
they do not, for example, inherit environment variable settings from it.
This change is specific to Debian see the note under DEBIAN SPECIFIC
below.