1753792 Members
7160 Online
108799 Solutions
New Discussion юеВ

Setting up cron job?

 
SOLVED
Go to solution
Becke
Super Advisor

Setting up cron job?

Guys
I need to set up a cron job, I need only three days output would be required of the data, between 00:00 and 02:00 each day.

"Suspect an overflow is occurring. I need to see the output from the below command, which should run 15 minutes apart. The problem would be it might not occur for any given 15 minutes, I really need it every 15 minutes between midnight and 2 am., so I would need to set up a script to run from cron, to run the command below and sleep for 15 minutes etc.

date +"%T"; ps -eo "%x %C %t %g %u %P %p %n %z %c" | grep ldapdb2


Would you please advise how to create a small script. Please let me know and also how to put an entry in crontab for every 15 minutes starting from midnight until 2am everyday

Thanks for your help
Raf
9 REPLIES 9
Peter Godron
Honored Contributor

Re: Setting up cron job?

Raf,
the quickest way via cron would be to have a job start at minutes 00,15,30,45 and then check within the script whether the hour is between 00 and 02.
If you specify the hours as 00,01,02 the job would be submitted from 00:00 to 02:45.

On how to set up your cron job, please see:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1037403
Becke
Super Advisor

Re: Setting up cron job?


Thanks Peter, I have worked it out on how to set up a cron job between 00 to 2am it should be like this,
0,15,30,45 00-2 * * * /scriptname > ouput

But I still need to know how to put the command below in a script,

"Suspect an overflow is occurring. I need to see the output from the below command, which should run 15 minutes apart. The problem would be it might not occur for any given 15 minutes, I really need it every 15 minutes between midnight and 2 am., so I would need to set up a script to run from cron, to run the command below and sleep for 15 minutes etc.

date +"%T"; ps -eo "%x %C %t %g %u %P %p %n %z %c" | grep ldapdb2,

Please advise
Peter Godron
Honored Contributor
Solution

Re: Setting up cron job?

Raf,
Have you tried editing your script and adding the lines
date +"%T"
ps -eo "%x %C %t %g %u %P %p %n %z %c" | grep ldapdb2


Any errors ?

Also your cron setup currently, means it runs 00:00 to 02:45 and will overwrite the outputfile everytime.

Replace > with >> before the outputfile to append.
Becke
Super Advisor

Re: Setting up cron job?


Hi Peter,

My script looks like this,

#!/usr/bin/ksh
date +"%T" >>/tmp/report
ps -eo "%x %C %t %g %u %P %p %n %z %c"|grep ldapdb2 >> /tmp/report

The above command runs successfully with no errors, however it just runs once as I need it to run every 15 minutes would it be okay to set a cron to run for every 15 minutes and that's that????
The problem would be it might not occur for any given 15 minutes, I really need it every 15 minutes between midnight and 2 am., so I would need to set up a script to run from cron, to run the command below and sleep for 15 minutes etc.

the cron entry should be below
0,15,30,45 0-2 * * * /tmp/cron.out 2>&1

if all the above is correct than I just need to configure a cron jon and that it? please advise

Thanks for your help





Borislav Perkov
Respected Contributor

Re: Setting up cron job?

Raf,
As you said just enter, in case your script full path is /mydirectory/myscript in crontab

0,15,30,45 0,2 0 0 0 /mydirectory/myscript

and you will have it execution every 15 minutes from 2:00 till 2:45

Regards,
Borislav
Borislav Perkov
Respected Contributor

Re: Setting up cron job?

ops
0,15,30,45 0,2 * * * /mydirectory/myscript
Sorry
Becke
Super Advisor

Re: Setting up cron job?


Thanks mate,

you say ops
0,15,30,45 0,2 * * * /mydirectory/myscript
Sorry

I need to run between 12pm and 2am and also don't specify - hyphen? or would it be ,

0,15,30,45 0-2 * * * /mydirectory/myscript
Becke
Super Advisor

Re: Setting up cron job?


sorry to 12 midnight to 2am not 12pm
Borislav Perkov
Respected Contributor

Re: Setting up cron job?

Yes thats wright 0-2 instead 0,2.