HPE Community read-only access December 15, 2018
This is a maintenance upgrade. You will be able to read articles and posts, but not post or reply.
Hours:
Dec 15, 4:00 am to 10:00 am UTC
Dec 14, 10:00 pm CST to Dec 15, 4:00 am CST
Dec 14, 8:00 pm PST to Dec 15, 2:00 am PST
cancel
Showing results for 
Search instead for 
Did you mean: 

cron job

 
SOLVED
Go to solution
S.S.
Super Advisor

cron job

Dear Experts,

I need to create a cron entry to execute a script.
I need to execute that script like for this year 2011 as
29th Jan,
26th Feb,
31st Mar,
28th April,
31st May,
30th June,
29th July,
30th Aug,
30th Sep,
28th Oct,
30th Nov and
29th Dec

and the time is at 10:30pm.

Please help me to create a cron job with the above and also explain me the entry how it works.

Thank you!

14 REPLIES
Shibin_2
Honored Contributor

Re: cron job

Add this line in your crontab using crontab -e

30 22 29 1 * <script>

This will run on Jan 29th @ 10:30pm. After this, you need to change the date and month to execute for next month.
Regards
Shibin
Shibin_2
Honored Contributor

Re: cron job

Another option

30 10 29 * * <script>

This will run on 29th of the month. You need to change the date to execute it on another date.
Regards
Shibin
nijokj
Trusted Contributor

Re: cron job

as simple,
you can put entries in crontab individualy for each month.
For eg: for Jan
30 10 29 1 * /path/script
Michal Kapalka (mikap)
Honored Contributor

Re: cron job

hi,

you could run the script every day,

and inside the script you will check if the current day ( os date ) is the same as your list of dates.

mikap
nijokj
Trusted Contributor

Re: cron job

for 10.30 pm jan 29

30 22 29 1 * /path/script
Jose Mosquera
Honored Contributor

Re: cron job

Hi,

Or include in your script a header that checks the execution on these specific days:

DAY_TO_EXECUTE=`date +%d%m`
case in $DATE_TO_EXECUE
do
2901|2602|3103|2804|3105|3006|2907|3008|3009|2810|3011|2912) **Include your procedure**
;;
*) exit
;;
esac

In this case you needs schedule a daily entry in your crontab to call the script, then the script only executes the conditions filtered into the case syntax.

Rgds.
Matti_Kurkela
Honored Contributor
Solution

Re: cron job

Since there seems to be no clearly-defined rule for when to run (like "last Saturday of each month"), I think a series of "at" jobs would be more appropriate.

echo "sh /path/to/the/script" | at 1030 Jan 29
echo "sh /path/to/the/script" | at 1030 Feb 26
echo "sh /path/to/the/script" | at 1030 Mar 31
echo "sh /path/to/the/script" | at 1030 Apr 31
echo "sh /path/to/the/script" | at 1030 May 31
echo "sh /path/to/the/script" | at 1030 Jun 30
echo "sh /path/to/the/script" | at 1030 Jul 29
echo "sh /path/to/the/script" | at 1030 Aug 30
echo "sh /path/to/the/script" | at 1030 Sep 30
echo "sh /path/to/the/script" | at 1030 Oct 28
echo "sh /path/to/the/script" | at 1030 Nov 30
echo "sh /path/to/the/script" | at 1030 Dec 29

For the next year, you'd have to set up a new set of at jobs; unlike cron jobs, at jobs are executed once and then removed from the list of scheduled jobs.

You might want to set up another job to remind yourself (or someone else) of that:

echo "mail -s 'REMINDER: set up a new series of at jobs for 2012' S.S@company.example" | at 1031 Dec 29

Use "at -l" to verify the list of at jobs.

In HP-UX, the cron daemon runs both cron and at jobs. Some other variants of Unix might have a separate "at daemon" for at jobs.

MK
MK
Manix
Honored Contributor

Re: cron job

MK given a wonderful solution with 'at' jobs
Looks at the alternatives gives by Dennis
using a shell script

http://h30499.www3.hp.com/t5/Languages-and-Scripting/Cron-job-scheduling-last-saturday-of-month/m-p/4739252#M29429

HP-UX been always lovable - Mani Kalra
Jose Mosquera
Honored Contributor

Re: cron job

Be careful with "at" large time scheduling, a system shutdown could happen meanwhile.

Rgds.
Matti_Kurkela
Honored Contributor

Re: cron job

And why should system shutdown affect 'at' jobs any different from 'cron' jobs?

In HP-UX, at job information is stored in /var/spool/cron/atjobs: I don't see anything that would clear them away at system shutdown/reboot cycle.

MK
MK
Jose Mosquera
Honored Contributor

Re: cron job

Matti, please excuse my previous opinion, you have absolutely right! :)
Canon_3
Occasional Advisor

Re: cron job

Dear Experts,
Thank you for your advises.

I have a query,
Let's say if i want to use cron scheduler then
suppose if i added all the entries starting from jan to dec in crontab file.
After successfully executed the script in Jan month. If i missed out to remove the Jan entry in crontab, even though also there shouldn't be any problem right?
Shibin_2
Honored Contributor

Re: cron job

It depends on how you entering in crontab.

Let's say, if you entered with date and month, then there is no problem, even if the entry exists. But if you only entered with date, then it will run again on next month.

Btw, are you the author of this question ? Pls assign points, if you satisfied with answers.
Regards
Shibin

Re: cron job

>Swetha: If I missed out to remove the Jan entry in crontab, even though also there shouldn't be any problem right?

It may have a problem if you don't want it to run a year later.