linux crontab 指定执行的用户

linux crontab 指定执行的用户。

一般来说我们通过crontab -e来添加定时任务, 但是如何优雅的指定该定时任务以哪个用户的身份来执行呢? 

方法是直接在/etc/crontab文件中追加定时任务 并制定用户(我的环境是Ubuntu linaro),如下

直接在/etc/crontab文件中添加,不过需要是root身份。打开文件,应该会看到类似下面的信息

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# 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

要添加新的crontab,只需要在文件最后增加即可。


猜你喜欢

转载自blog.csdn.net/tt361/article/details/50205725