Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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
share|improve this answer
    
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 –  Jeevan Dongre Nov 18 '11 at 8:16
    
If you already includes sudo before the required commands, no need to put it in cron job. –  quanta Nov 18 '11 at 8:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.