cronjob with highest privilege

Amin El-Zein
Amin El-Zein used Ask the Experts™
I have a FreeBSD and ubuntu server.
I crate a cronjob to execute in specific time. but the command that I do required a full privilege on system... so how I can make the cronjob work with root for example ?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
David FavorFractional CTO
Distinguished Expert 2018

You do something like this...

sudo crontab -e

Open in new window

This will put you into the CRON entries for the root user.
Linux Admin
First you need to add user in /etc/sudoers file.
and add below-mentioned line.


After run  #crontab -e
 * * * * * /usr/bin/sudo /command or else script you want to run
Gerwin Jansen, EE MVETopic Advisor
Most Valuable Expert 2016

You can either just logon as root and create the crontab entry or create a crontab entry and get sudo rights for the command (or commands) that need higher privileges. I'm preferring the last as it enables you to test your script more easily and you don't have to put anything in the root crontab. What command are you trying to run btw?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial