crontab:哪个是正确的工作定义?
crontab: which one is the right job definition?
crontab
工作的正确定义是什么?
执行路径前有或没有 user
?
.---------------- minute (0 - 59)
| .------------- hour (0 - 23)
| | .---------- day of month (1 - 31)
| | | .------- month (1 - 12) OR jan,feb,mar,apr ...
| | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
| | | | |
* * * * * <user> <command>
在 Debian 上,crontab -l
将备份示例显示为:
....
For example, you can run a backup of all your user accounts
at 5 a.m every week with:
0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
...
这里没有user
!!
/etc/crontab
内容(在同一个盒子上),给出了不同的线索:
....
and files in /etc/cron.d. These files also have username fields,
that none of the other crontabs do.
...
crontab
不 * 允许将用户指定为 运行 为...
...除非您在根 crontab 中。
如果您查看我的 favorite linux admin reference,您将不会发现有一些技巧可以将某些 chrontab 条目作为特定用户 运行。但是,如果您愿意,最好的做法是编辑用户的 crontab:
crontab -u <username> -e
如果你必须...
0 0 * * * sudo -u [user] [command]
但这只能在具有 sudo 权限的用户的 crontab 中完成,正如 fcm 指出的那样,这样的用户只能编辑根 crontab。
'NIX 的大多数版本都需要根 crontab 中的用户 /etc/crontab
0 0 * * * [user] [command]
结论
如果您想指定哪个用户正在 运行 执行特定的 cron 作业,最佳做法是执行以下操作之一,具体取决于用例:
- 根 crontab
- /etc/crontab
sudo crontab
<time> <user> <command>
- 用户 crontab
crontab -u <username> -e
<time> <command>
crontab
工作的正确定义是什么?
执行路径前有或没有 user
?
.---------------- minute (0 - 59)
| .------------- hour (0 - 23)
| | .---------- day of month (1 - 31)
| | | .------- month (1 - 12) OR jan,feb,mar,apr ...
| | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
| | | | |
* * * * * <user> <command>
在 Debian 上,crontab -l
将备份示例显示为:
....
For example, you can run a backup of all your user accounts
at 5 a.m every week with:
0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
...
这里没有user
!!
/etc/crontab
内容(在同一个盒子上),给出了不同的线索:
....
and files in /etc/cron.d. These files also have username fields,
that none of the other crontabs do.
...
crontab
不 * 允许将用户指定为 运行 为...
...除非您在根 crontab 中。
如果您查看我的 favorite linux admin reference,您将不会发现有一些技巧可以将某些 chrontab 条目作为特定用户 运行。但是,如果您愿意,最好的做法是编辑用户的 crontab:
crontab -u <username> -e
如果你必须...
0 0 * * * sudo -u [user] [command]
但这只能在具有 sudo 权限的用户的 crontab 中完成,正如 fcm 指出的那样,这样的用户只能编辑根 crontab。
'NIX 的大多数版本都需要根 crontab 中的用户 /etc/crontab
0 0 * * * [user] [command]
结论
如果您想指定哪个用户正在 运行 执行特定的 cron 作业,最佳做法是执行以下操作之一,具体取决于用例:
- 根 crontab
- /etc/crontab
sudo crontab
<time> <user> <command>
- 用户 crontab
crontab -u <username> -e
<time> <command>