1748063 Members
5391 Online
108758 Solutions
New Discussion юеВ

Re: 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 14
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.