1829116 Members
2294 Online
109986 Solutions
New Discussion

cron jobs in unix

 
harikrishna
Advisor

cron jobs in unix

how to i set a cron job in hp unix server to execute a script.

THANKS FOR ALL THE REPLIES

Regds,
HARI KRISHNA
3 REPLIES 3
Sridhar Bhaskarla
Honored Contributor

Re: cron jobs in unix

Hi,

You will need to make sure your login is added to /var/adm/cron/cron.allow (link from /usr/lib/cron/cron.allow) file.

Once it is there then you can use the command
'crontab -e' to invoke editor. Look at 'crontab' man page for more details on formats. The syntax is basically the following

minute hour monthday month weekday command

to run a script called /home/sridhar/mycron.sh every 15 mins, i would add the entry as

0,15,30,45 * * * * /home/sridhar/mycron.sh > /dev/null 2>&1

Once an entry is added, save the file and it should add it to cronjobs. Subsequent entries can be placed using the same command 'crontab -e'.

Alternatively, you can create a file with crontab syntax and run the command 'crontab filename' to add the entries in that file to cron.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Hoefnix
Honored Contributor

Re: cron jobs in unix

To be allowed to schedule a cronjob as a user you have to edit the file:
/var/adm/cron/cron.allow

This file contains a list of usernames that may schedule jobs

Then became the user that wants to schedule someting and do:
crontab -e

You come in a vi session of the schedule of the current user:

Format of the file:

# Minute Hour Month Day Month Command to run
# ----------------------------------------------------------
0 01 * * * Job_1
0 02 * * * Job_2
0 03 * * * Job_3
0 04 * * * Job_4
0 * * * * Job_hourly
0 2,3,4 * * * Multiple_1
0 2,4 * * * Multiple_2


Save the file with :x

check your schedule with the command "crontab -l"

Regards,

Peter
Elmar P. Kolkman
Honored Contributor

Re: cron jobs in unix

Some things to bear in mind:
1) output from cronscripts is mailed to the owner of the crontab
2) your PATH settings are minimal. Specify commands with absolute pathnames or set your PATH environment variable in the scripts (I would do the latter. Makes testing more fool-proof. In vi you can do:
!!set|grep '^PATH='
to replace the current line with your current PATH environment variable.)

Every problem has at least one solution. Only some solutions are harder to find.