cron 作业的运行时权限是什么?

Jim*_*Jim 20 cron permissions

当 cron 作业以什么权限运行时,它会执行什么?

对此我不确定。它是否与通过添加它的用户具有相同的权限crontab -e

slm*_*slm 22

You can specify a user in the system crontab entries like so:

# For details see man 4 crontabs

# Example of job definition:
.---------------- 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-name  command to be executed
Run Code Online (Sandbox Code Playgroud)

The 6th argument can be a username. Additionally you can put scripts in the /etc/cron.d directory. The scripts take the same form as the crontab entries described above, for example:

# /etc/cron.d/clamav-update
## Adjust this line...
MAILTO=root

## It is ok to execute it as root; freshclam drops privileges and becomes
## user 'clamav' as soon as possible
0  */3 * * * root /usr/share/clamav/freshclam-sleep
Run Code Online (Sandbox Code Playgroud)

You can put scripts in these directories, but they're meant to be run as root:

  • cron.daily
  • cron.hourly
  • cron.weekly
  • cron.monthly

Finally you can create user based crontab entries by running this command as a given user:

$ crontab -e
Run Code Online (Sandbox Code Playgroud)

These entries are stored in files with the same name as the user in this directory, /var/spool/cron/:

$ sudo ls -l /var/spool/cron/
-rw------- 1 saml root 0 Jun  6 06:43 saml
Run Code Online (Sandbox Code Playgroud)


han*_*rak 5

是的,但是,除非您指定另一个用户,否则手动添加到系统 crontab(编辑 /etc/crontab)的作业将以绝对权限运行(即:以 root 身份运行)。