Is it possible to run a cron job which needs the sudo command?
Like:
sudo rm somefile
|
|
I won't get into how much this is a bad idea; simply put, running It's a bad idea. The following is the preferred method of running administrative tasks through cron. Since you don't really need to write Use root's crontabRun the following command:
This opens up Therefore, you would simply append the following to root's crontab.
Now, if you absolutely want to be unsafe and take risks with your password, the following will run your command from your own crontab, and enter your password automatically when prompted by Again, this is not recommended. In your own crontab, write your command like so:
The obvious disadvantage here is that, should anyone ever access your crontab, your password will be readable in plaintext. You shouldn't do this. |
|||||||||||||||||||||
|
|
If you are putting the script from one of the cron directories ( If you are using crontab, then you will want to use root's crontab. This will run it as root, and also not need sudo.
|
|||||||||||||
|
|
Run following command in terminal
Added the following line to the end of the file:
In the above example vidyadhar is the username and it will not ask for password if you are running rm command through vidyadhar. |
|||||||||||||||||
|