1745808 Members
3772 Online
108722 Solutions
New Discussion юеВ

cron question

 
SOLVED
Go to solution
wvsa
Regular Advisor

cron question

Good afternoon;

IS there any way to setup a cron entry that runs every 15 minutes from 5am to 9pm. Don't think it is possible but thought I'd ask someone who is smarter than I.


Norm
8 REPLIES 8
Steven Schweda
Honored Contributor

Re: cron question

There might be, but it might be easier to
have cron run a script every 15 minutes, and
have that script look at the time to see if
it should do anything.
Patrick Wallek
Honored Contributor
Solution

Re: cron question

What about the following:

00,15,30,45 5-20 * * * /do/something
00 21 * * * /do/something

The first entry will run every 15 minutes from 5:00 AM to 8:45 PM. The 2nd entry will run at 9:00 PM.

If you were to specify the hours of the first entry as 5-21, then your script would run at 9:00 PM, 9:15 PM, 9:30 PM and 9:45 PM, which is not desirable, if I read your question correctly. Thus, the 2 step process.
wvsa
Regular Advisor

Re: cron question

Hello Steven;

Good idea, not sure how to do that in the script, here is the script:

ps -ef | grep -i "httpd.conf -k" | grep -v grep
if [ $? = 0 ];then
echo "Zend is running on ${HOST} OK at `date`" >> $HISTFILE
else
sleep 1
echo "Zend down on $HOST at `date`" > $MAILFILE1
cat $MAILFILE1 | mailx -s "Zend_Down on $HOST" root
cat $MAILFILE1 >> $HISTFILE
fi


Let me know if you have a idea of how to get this script to look at time and not run the if statement.

Thank you

Norm
wvsa
Regular Advisor

Re: cron question

Patrick;

Excellent!!!

Thank you

Norm

Steven Schweda
Honored Contributor

Re: cron question

> [...] how to get this script to look at
> time [...]

man date

x=$(date +%H)
echo $x

Test the hour in a preliminary "if"
statement.

> [...] Thus, the 2 step process.

You'd probably need to do that (and look at
the minutes, "%M") with this scheme, too.
Some clever string comparisons might be
easier than looking at the numbers as
numbers.
Jared Middleton
Frequent Advisor

Re: cron question

Combine Patrick and Steven:

# Cron run every 15 min from 5:00am to 9:45pm
00,15,30,45 5-21 * * * myscript

# Top of myscript
[ $(date +%H%M) -gt 2100 ] && exit


wvsa
Regular Advisor

Re: cron question

Hello Jared;

Patrick response did the trick, I need to only run the script until 9pm. Will try your add to the script.


Thank you


Norm
Jared Middleton
Frequent Advisor

Re: cron question

Actually, I was only showing what COULD be done, not what SHOULD be done. I wouldn't recommend hardcoding a time-based exit in a script... because someone later might want it run at 11pm or whatever, and it would fail. So, if you do include it, comment it well with the rationale/assumptions.