问题描述
我有几个 bash 脚本会添加到指定时间的 cron 作业中,但需要以 root 用户身份执行.我正在尝试运行这些脚本,即 crob 作业,但它需要 root 用户权限,因为我在 root 用户受限的 ubuntu ec2 实例中运行这些作业.以 root 用户身份运行这些脚本的解决方法是什么.
谢谢
有几种可能:
1) 将脚本添加到 root 的 crontab 中.为此,您必须执行 sudo su -
或 su -
以成为 root,然后使用 crontab -e
添加 cron 作业>
2) 允许非 root 用户使用 crontab,并使用 crontab -e
将 cron 作业添加到该用户的 crontab 中and 设置脚本的 set-uid 标志并将所有权更改为 root,因此它将以 root 身份执行 chmod +s scriptname;chown root 脚本名
I have few bash scripts which are adding to cron jobs with specified timing, but it needs to be executed as root user. I am trying to run those scripts i.e., crob jobs but it needs root user permission, since I am running this jobs in ubuntu ec2 instance where root user is restricted. What would be the work around to run those scripts as root user.
Thanks
There are several possibilities:
1) add the script(s) to the crontab of root. To do this you have to do sudo su -
or su -
to become root, then add the cron jobs by using crontab -e
2) allow a non-root user to use a crontab, and add the cron job to that user's crontab , by using crontab -e
and set the set-uid flag of your script and change ownership to root, so it will execute as root chmod +s scriptname; chown root scriptname
这篇关于如何以用户而不是 root 用户身份运行 cron 作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!