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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cron on AIX

Status
Not open for further replies.

Learnr

Programmer
Jul 29, 2004
2
US
Hi,

I am learnig how to use Cron..And I have some basic questions..

1. Can I use Cron on AIX system.
2. Can I use it to run some database commands at certain intervals..If so how?
3. Can the database be DB2.

Any help in this regard is appreciated.
Thanks
 
1. Yes

2. Yes. I paste the following into my crontab as a reminder as to what the order of fields is:

#Crontab field order:
#minute (0-59),
#| hour (0-23),
#| | day of the month (1-31),
#| | | month of the year (1-12),
#| | | | day of the week (0-6 with 0=Sunday).
#| | | | | commands

You edit the crontab using crontab -e and make entries like the following - based on the above:

00 11 * * 0-6 "<script to run>"

This runs the script at 11:00 am every day. Save your crontab using wq!, as in vi.

3. I see no reason why db2 shouldn't be the same as any other database. We use Oracle and make entries of the type:

00 11 * * 0-6 su - oracle -c "<script to run>"

which runs the script under the Oracle user id. You can of course make a crontab for user Oracle or whoever if that's what you prefer. Bear in mind that cron uses a very restricted environment, so it may be necessary to explicitly set environment variables ($PATH etc) within the script itself - this is a common gotcha.

Hope this helps and good luck.
 
It's also a good idea to backup the crontab before you change it, like so:

crontab -l > crontab.30jul2004

Then, if you want to revert to the backed up table, you can do:

crontab crontab.30jul2004





Rod Knowlton
IBM Certified Advanced Technical Expert pSeries and AIX 5L

 
And beware the typo 'crontab -d'
Yes, I know all we Unix Admins would never make a mistake that dumb, would we!
 
'l' is also safely distant from 'd' on my QWERTY keyboard, unlike 'e'. Who among us has never had their fingers on the incorrect home row? :)

I don't actually use 'crontab -e' at all. I make my backup, copy that backup to something like "crontab.new", edit it and then submit it with "crontab crontab.new". I know that -e is probably safe after I make the backup, but copying and editing confirms that the backup is good. Besides, I'm a belt and suspenders kind of guy when it comes to system modification.

Rod Knowlton
IBM Certified Advanced Technical Expert pSeries and AIX 5L

 
Thank you all for the info. It is very helpful.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top