Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

crontab 2

Status
Not open for further replies.

Scunningham99

Programmer
Sep 20, 2001
815
GB
I Have the following entries in by conrtab.

they are to to shut databases down at two different times.

mon-sat and on ecevy sun at different times. basicallyu my boss has got arse ache, and he seems to think this can be done in one line. any clues:-

#00 8 * * * /usr/local/bin/db-startup.script #startup script every day
#00 23 * * 0-6 /usr/local/bin/daily_backup_dbf 1>/tmp/db.err 2>&1

CAN THE ABOVE CRONTAB ENTRIES BE DONE IN ONE LINE?????

THANKS IN ADVANCE

SY
 
As your scripts are scheduled to run at completely different times, this isn't possible. An alternative might be to combine the scripts (say, have the backup first then the startup) and set an entry in crontab to run it at an appropriate time. Hope this helps anyway.
 
crontab allows one command per line, so if you wanted to run more commands, you would call in a single script to execute a many instructions as wanted. However as one job runs ar 8 a.m and the other at 11 p.m you have a time difference. What is your boss's real problem? Surely not worried about one line of crontab?
 
sorry guys heres the correct entry from crontab

30 23 * * 1-6 /usr/local/bin/db-shutdown.script # mon - sat
30 20 * * 0 /usr/local/bin/db-shutdown.script # every sun

can this be done as one. i dont think so, any clues

 
Because you're running these scripts in a mutually exclusive way (ie one runs Monday - Saturday, and the other runs on a Sunday), it's difficult to envisage how you would call them from one crontab entry. That is unless you can combine the two and test what day it is. The result of this test could then be used to run whichever script is 'due'. Of course, this again relies on your being able to have the scripts run at the same time each day, rather than at two separate times as at present.

date +%a

will give you the abbreviated day to use in such a test, so you could have a script in crontab something like:

DAY=`date +%a`
if [ $DAY = 'Sun' ]
then
<run the Sunday job>
else
<run the Mon - Sat job>
fi

Hope this helps.
 
I don't think you can do much better than follow Ken's recommendations.
 
Don't forget to change your crontab to * * * so the one script will run everyday

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top