0

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

1 Answer 1

3

I'm not familiar with EC2, but you can define a list of commands which can be executed by sudo without password prompt. Run visudo and insert something like this:

Cmnd_Alias     CRONJOB = /full/path/to/command1, /full/path/to/command2, ...
<your_user>  ALL=(ALL)   ALL, NOPASSWD:CRONJOB

after that just use sudo in the bash scripts and put these in your cron job.

*/1 * * * * /path/to/the/script1
* */2 * * * /path/to/the/script2
2
  • ubuntu ec2 instance by default does not ask for the password even if I includes sudo before any command but how do I prefix it in the cron job so that cron runs particular script with sudo prefixed to that Nov 18, 2011 at 8:16
  • If you already includes sudo before the required commands, no need to put it in cron job.
    – quanta
    Nov 18, 2011 at 8:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .