1752570 Members
5175 Online
108788 Solutions
New Discussion юеВ

configuring cron job

 
SOLVED
Go to solution
Shivkumar
Super Advisor

configuring cron job

I have writeen one small shell script and want to configure as cron job. what is the best method to configure it as a cron job ?
20 REPLIES 20
Ken O'Neil
Frequent Advisor

Re: configuring cron job

Log in as the user you want to run the script, then run `crontab script_name`. Check `man crontab` for additional info.
Victor Fridyev
Honored Contributor

Re: configuring cron job

Hi,

The main problem when you write a script, which should run in crontab is environment, mainly PATH. When a script runs from crontab, it's PATH contains /bin and /usr/bin. Because of that, all commands should be used with their full path. In order to simplyfy the problem, put in the beginning of the script
. ~/.profile
or to create a file which contains all needed variables and download it.

HTH
Entities are not to be multiplied beyond necessity - RTFM
James R. Ferguson
Acclaimed Contributor
Solution

Re: configuring cron job

Hi Shiv:

First, read the manpages for 'crontab(1)'. This is really quite explanatory.

Make sure that your login is allowed in '/var/adm/cron/cron.allow'.

Personally I prefer to write any current crontab to a file; edit that file; and lastly replace the current crontab file with the editted one. Others will use the direct edit option of 'crontab' using '-e'.

Thus, method-1 is:

# crontab -l > $HOME/crontab
[ edit $HOME/crontab ]
# crontab $HOME/crontab

Method-2 is:

# crontab -e

Method-2 simply invokes 'vi' using a temporary version of your crontab file (under the account you are logged into, of course). When you write/quit the editted version, your crontab is replaced.

My preference in using method-1 is that I mangle the editting in any way, I can simply discard the file, or write (save) what I have and fix it again before I apply it.

Regards!

...JRF...
Shivkumar
Super Advisor

Re: configuring cron job

The scritp names is say "tulip.sh" and i want execute at 2.25am every day. what should be the syntax ? thanks.
James R. Ferguson
Acclaimed Contributor

Re: configuring cron job

Hi Shiv:

25 02 * * * $HOME/tulip/sh

...where "*" means "every" and the fields are:

minute hour monthday month weekday command

Shiv, I encourge you to use the manpages as a resource. They are meant to be reference material and do assume some knowledge, *but* the more you read them, the more comfortable you will become with trying to read them. Usually you will find examples in the discussion which can be related easily to the initial synopsis (syntax).

The structure of the HP-UX manpages is described here (below). As a user and as an administrator, you will spend most of your time in sections 1 and 1M. A great deal of information on configuration files appears in section-4. Section-9 has a very good glossary.

http://www.docs.hp.com/en/B2355-60127/Introduction.9.html

Regards!

...JRF...
Muthukumar_5
Honored Contributor

Re: configuring cron job

try as,

25 02 * * * Full path to script 1>/dev/null 2>&1

Example:

25 02 * * * /home/shiv/tulip.sh 1>/dev/null 2>&1


See crontab man page more.

--
Muthu


Easy to suggest when don't know about the problem!
Arunvijai_4
Honored Contributor

Re: configuring cron job

Hi Shiv,

You asked about, The scritp names is say "tulip.sh" and i want execute at 2.25am every day. what should be the syntax ?

25 02 * * *

-Arun

"A ship in the harbor is safe, but that is not what ships are built for"
Yogeeraj_1
Honored Contributor

Re: configuring cron job

hi,

My typical crontab looks as follows:

25 02 * * * /home/shiv/tulip.sh 1>/dev/null 2>&1
#*******************************************************************************
# min|hour |day |month|day |script
# | |of mo| |of wk|
#----|-----|-----|-----|-----|--------------------------------------------------
#*******************************************************************************
#*******************************************************************************
# END OF TABLE day0->Sunday day6->Saturday
#*******************************************************************************


hope this helps!

kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Arunvijai_4
Honored Contributor

Re: configuring cron job

Hi Shiv,

A great introduction about "Cron"

http://www.unixgeeks.org/security/newbie/unix/cron-1.html

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"