linux crontab 指定执行的用户。html
通常来讲咱们经过crontab -e来添加定时任务, 可是如何优雅的指定该定时任务以哪一个用户的身份来执行呢? linux
方法是直接在/etc/crontab文件中追加定时任务 并制定用户(个人环境是Ubuntu linaro),以下bash
直接在/etc/crontab文件中添加,不过须要是root身份。打开文件,应该会看到相似下面的信息post
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,只须要在文件最后增长便可。spa
本文首发于姜哥的墨迹技术博客(blog.mojijs.com)。
本文地址为http://blog.mojijs.com/post/175.html(blog.mojijs.com/post/175.html)。更多精彩请关注原文。htm