1835195 Members
2582 Online
110077 Solutions
New Discussion

Re: crontab

 
Adrian_72
Advisor

crontab

Do you have any example for execute a script in the crontab file?

7 REPLIES 7
Rick Garland
Honored Contributor

Re: crontab

min hr day_of_month month day_of_week

Example
0 1 15 * * /usr/local/bin/my_script

Execute /usr/local/bin/my_script at 0100 hrs on the 15th day of every month.

0 1 * * *
execute everyday at 0100 hrs.

Pete Randall
Outstanding Contributor

Re: crontab

Something like this:

########################################################
# Check to see if it's necessary to make a new recovery tape
#
00 05 * * 1 /opt/ignite/bin/check_recovery
#

would run check_recovery at 5 minutes after midnight on Monday.


Pete

Pete
A. Clay Stephenson
Acclaimed Contributor

Re: crontab

It is very important that you do not edit the cron files directly. For one thing, the cron daemon wouldn't have a clue that you have done anything.

You should do something like this:

Login (or su) as the appropriate user.
crontab -l > /var/tmp/mycrontab
edit /var/tmp/mycrontab to add an entry as indicated in the above responses.
crontab < /var/tmp/mycrontab

Running the crontab command without -l has the effect of reading stdin and sending a SIGHUP to the cron daemon to let it know it should reread the file. Man crontab for details.

A common error when building scripts that are run by cron is not explicitly setting and exporting needed environment variables (including PATH) in the script itself. Cron has an intentionally very sparse environment.
If it ain't broke, I can fix that.
Geoff Wild
Honored Contributor

Re: crontab

I tend to do:

crontab -e

when editing...

Here's a sample entry:

0 6 21 * * [ -d /var/adm/lp/XEBEC ] && /usr/local/bin/lpqpurge >/tmp/lpqpurge.cronlog 2>&1


What it does:

at 6 am on the 21st day of every month, it checks to see if the filesystem /var/adm/lp/XEBEC exists - if yes - it then executes the script called /usr/local/bin/lpqpurge.

the >/tmp/lpqpurge.cronlog 2>&1 tells cron to send any output and / or errors to a logfile called /tmp/lpqpurge.cronlog

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Senthil Kumar .A_1
Honored Contributor

Re: crontab

Well i hope u will never forget this

MHDMW - mad husband doubt mad wife :)
- minute hour day month week.

Remember if you donot redirect your command outputs/error, by default crond will mail the respective owner.

A bit of advice always use "crontab -e" to edit a cron entry entry.

Let your effort be such, the very words to define it, by a layman - would sound like a "POETRY" ;)
Alex Lavrov.
Honored Contributor

Re: crontab

LOL, great Senthil, I'll remember that one ;) he he
I don't give a damn for a man that can only spell a word one way. (M. Twain)
Rob van Buiten
Regular Advisor

Re: crontab

Adrian,

put this heading in your crontab:
##############################################################################################
## minute hour day_month month_year day_week program [argument(s)] ##
## (0-59) (0-23) (1-31) (1-12) (0-6 with 0=Sunday) ##
##############################################################################################

Paul.