How can I run a command in a shell script using sudo? This script will be executed by a cron job, so there should be no human intervention to enter the password manually.
echo 'password' | Sudo -S command
Enter cronjob in
sudo crontab -e
then the whole script will be executed as root by default without the need for a password.
Why not run the script itself as root in cron, as this is basically what sudo will do? Are you talking about the user crontab?
I think you are trying to do this:
user# crontab -e * * * * * sudo ./code_here
But every time the script is called to provide credentials
So, you can try this:
user# sudo su root# crontab -e * * * * * ./code goes here
Thus: it will run with administrator rights.