如何以用户而不是 root 用户身份运行 cron 作业 [英] How to run the cron job as a user instead of root user

查看:133
本文介绍了如何以用户而不是 root 用户身份运行 cron 作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个 bash 脚本会添加到指定时间的 cron 作业中,但需要以 root 用户身份执行.我正在尝试运行这些脚本,即 crob 作业,但它需要 root 用户权限,因为我在 root 用户受限的 ubuntu ec2 实例中运行这些作业.以 root 用户身份运行这些脚本的解决方法是什么.

谢谢

解决方案

有几种可能:

1) 将脚本添加到 root 的 crontab 中.为此,您必须执行 sudo su -su - 以成为 root,然后使用 crontab -e

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 作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆