1850106 Members
5809 Online
104050 Solutions
New Discussion

Re: Cronjob

 
harikrishna
Advisor

Cronjob

Hi All,
can anyone help me in setting cron job on HP-UX server.

Thanks in advance.

Regards,
Krishna

7 REPLIES 7
Michael Tully
Honored Contributor

Re: Cronjob

Below I run a script called diskspace.sh
The first are are the minutes of the hour. The second 7-18 which means I want to only run it between the hours of 7AM and 6PM (24 hour clock). The next is the day of the month, the number of the Month and finally the Weekday.

1,16,31,46 7-18 * * 1-5 /techsupp/util/diskspace.sh -e"sysadmin"

The idea of cron is to run the job only. All variables, commands etc are embedded in the script or program
Anyone for a Mutiny ?
T G Manikandan
Honored Contributor

Re: Cronjob

Just do a
$crontab -e

Then add the entry to the crontab file as stated earlier.

30 * * * * /opt/diskmon.sh

30 * * * * fields denote,

minute The minute of the hour, 0-59 hour The hour of the day, 0-23
monthday The day of the month, 1-31
month The month of the year, 1-12
weekday The day of the week, 0-6, 0=Sunday

So above I am running a script every thirty minutes all thru' the year.

check man crontab
harikrishna
Advisor

Re: Cronjob

Hi ,
thanks for your reply.But I know the syntax of cron,i don't know where to set the cron.can please send me where and how we will send the cron job of my script

Thanks for your help.

Regards,
Hari Krishna
Mobeen_1
Esteemed Contributor

Re: Cronjob

Krishna,
The steps you need to follow in setting up a cronjob are as follows

1. crontab -e

2. scroll down to the last line and insert
a line

3. Then as per Michael's instructions
submit your script

4. The typical entry on the line that
you inserted will look something like
what Michael has illustrated nicely

1,16,31,46 7-18 * * 1-5 /techsupp/util/diskspace.sh -e"sysadmin"

where diskspace.sh is your script and other descriptions are as mentioned by Micahel in the post prior to this

Let us know if you have any questions

regards
Mobeen
Michael Tully
Honored Contributor

Re: Cronjob

Please, have a good read of both the 'cron' man page and 'crontab' man page. From this and the instructions we have given you, you should be okay.
Anyone for a Mutiny ?
harikrishna
Advisor

Re: Cronjob

Hi Mobeen,
Thanks for your response.


Thanks once again to all

Regards,
Krishna
Sanjay Kumar Suri
Honored Contributor

Re: Cronjob

Some Notes:

The cron daemon is started during the system boot process and executes time scheduled jobs.
# ps -ef | grep crom # is cron running?
# cron # start the cron daemon, if it isn't currently running

Jobs are submitted to cron with crontab command. Root controls who can use crontab through /var/adm/cron/cron.allow file.

If cron.allow does not exist then /var/adm/cron/cron.deny is checked to determine if the user should be denied access. If both exist, cron.allow takes precedence. If neither file exists, only root is allowed to submit a job.
An empty cron.deny file allows all to use crontab.

Each user that is using the cron daemon should have a cron configuration file in the /var/spool/cron/crontabs directory. The cron daemon consults the files in this directory to determine which jobs should be executed when A % character in the command field (unless escaped by \) is translated as a new-line character.

You must redirect standard output and standard error of your commands. If you don't, any output generated will be mailed to you. Examples:

# min hour date month day command
# 0-59 0-23 1-31 1-12 0-6 be sure to redirect output!
0 * * * * /usr/bin/date >/dev/console
0 6 1,15 * * >/var/adm/btmp
0 5 * * 1-5 /usr/bin/who | /usr/bin/lp

Always use full path names for commands and files names, since cron uses only the standard environment of /usr/bin/sh and doesn't know about your environment.
# crontab -e # edit and submit a cron file
# crontab -l # view your cron file
# crontab -r # remove all your scheduled cron jobs.

By default crontab opens the user's own cron file. However system administrator can modify any user's cron file by command: crontab -e user1

Cron log file /var/adm/cron/log should be checked and emptied regularly. Although the files in /var/spool/cron/crontabs can be viewed with ls and cat, they should never be edited or removed. Doing so can leave the cron daemon in an undefined state.
Always use the crontab command when making changes to scheduled cron jobs.

sks
A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.