[ILUG-BOM] Cron help needed
prasad.raghu.k at gmail.com
Mon Nov 26 17:22:34 IST 2007
> using crontab -e i have created the crontab file and gave the
> specified time and commands.
> Then when i start crond its says cant' lock pid....
> Other wise can anyone tell me how to put shell script in crontab.
1. Write a shell script in a secure location. For example, assume that
your script is /usr/local/bin/myscript.sh
2. Make sure that its owner and group is root and root respectively.
chown root.root /usr/local/bin/myscript.sh
This step is not essential, but useful to keep the script tamper proof
provided next step is also followed.
3. Make sure that it is executable.
chmod 755 /usr/local/bin/myscript.sh
4. Run "crontab -e" as the user who is intended to execute the script.
In the editor window, enter data in the following format (for further details
read crontab manual by running "man 5 crontab")
minute hour day_of_month month day_of_week /usr/local/bin/myscript.sh
For testing purpose, set up execution time a few minutes from current time.
Usually cron daemon is started during system startup. You don't have to
start it explicitly. Run "ps -ax | grep cron | grep -v grep" to check whether
cron is running already.
5. Check the mail of the user as whom the script was getting executed.
The mail will contain the output, if any, generated from the script. Usually
these mails are stored in /var/mail directory.
Special care should be taken to write scripts running as root. The ownership
and permission of all the scripts or other executables are of extreme
importance to avoid unintended security holes in your setup. The security
aspects of shell script or any other executable can't be discussed in a short
mail like this. Refer some good books on secure programming or search on
More information about the Linuxers