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 -orsu -to become root, then add the cron jobs by usingcrontab -e2) allow a non-root user to use a crontab, and add the cron job to that user’s crontab , by using
crontab -eand 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