[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2213
  • Last Modified:

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?
0
virtualworks
Asked:
virtualworks
1 Solution
 
juanolleCommented:
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
0
 
michofreihaCommented:
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

0
 
virtualworksAuthor Commented:
Great. Will that be run as root user?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
michofreihaCommented:
yes
0
 
michofreihaCommented:
of course if you login as root to the server and add this line to crontab, anyway test it and let me know
0
 
omarfaridCommented:
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
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now