Crontab - shell script as root

I have a shell script that needs to be executed once a day automatically. Every command within the script needs to be run as root.

How do I do this?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Add this to bottom of your /etc/crontab file. Just edit yours script in it. You can also change time when it's executed (this executes 05:00) ..

00 5 * * *  root /path/to/yours_script

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
do the following:

#crontab -e

and add the following line inside the crontab:

0 12 * * * /usr/share/bin/alarm would run a script called alarm every day at noon

virtualworksAuthor Commented:
Great. Will that be run as root user?
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

of course if you login as root to the server and add this line to crontab, anyway test it and let me know
To add, please make sure that

- All needed env variables are set in the script
- Use full path names of commands used e.g /usr/bin/ls
- Use full path names for files used e.g. /path/to/myfile
- Redirect output to log files e.g.

/usr/bin/command > /path/to/myscript.log 2>>&1
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux Distributions

From novice to tech pro — start learning today.