Creating crontab for non-root user

一笑奈何 提交于 2019-12-12 02:46:02

问题


I am attempting to run a script through crontab that is required to run as an oracle user. I have tried creating a crontab for that user by: su -u oracle crontab -e which has allowed me to create one. I edited the file to run a perl script:

0 5 * * * /usr/bin/perl /path/master.pl > /tmp/debug.log

However when the time passes nothing is run. Is this the proper way to create a crontab for non-root user? Also the master.pl file call multiple scripts that also need to be done as a oracle user if that makes a difference.


回答1:


Use crontab's -u option. The man page says:

-u Appends the name of the user whose crontab is to be modified. If this option is not used, crontab examines "your" crontab, i.e., the crontab of the person executing the command. Note that su(8) may confuse crontab, thus, when executing commands under su(8) you should always use the -u option. If no crontab exists for a particular user, it is created for him the first time the crontab -u command is used under his username.

So the correct command is:

sudo crontab -e -u oracle


来源:https://stackoverflow.com/questions/33569743/creating-crontab-for-non-root-user

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!