- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Cron Question/Suggestion.
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2004 10:12 AM
11-05-2004 10:12 AM
I had a question and as well as an answer to the cron scheduling below. Please tell me if i am correct.
1. How I can run after each 14 Days.
2. How I can make sure that the job is running on the first working day of the month.
Taking only Sat-Sun into account for Holidays.
Answer...
For both requirements, some logic has to be built into the program that is to be run thro' cron. The cron tab entry may be set as:
1. <>
2. 0 0 1-7 * * <
The <
Is this correct? Please let me know?
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2004 10:40 AM
11-05-2004 10:40 AM
SolutionYes. For both you will need to build logic into your script itself.
1. Have a script schedule it again after 14 days using 'at' command. "at" command allows you to specify offset in 'weeks'.
2. You can scedule your job to run for the first three days only looking for the following conditions.
Date Don't run Run if
---- --------- -------
1 Sat,Sun Mon - Fri
2 Tue - Sun Mon
3 Tue - Sun Mon
You have to run it on 3rd also because 2nd could be a sunday.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2004 10:45 AM
11-05-2004 10:45 AM
Re: Cron Question/Suggestion.
For 1)
Make a crontab entry that looks like this:
15 18 * * 1 /usr/local/bin/myscript.sh
to run at 18:15 every Monday, for example. That runs every 7 days so now your script needs some logic to run every other week.
#!/usr/bin/sh
PATH=${PATH}:/usr/local/bin
export PATH
typeset -i WEEKNO=$(( ($(cajld.sh) + 1) / 7))
typeset -i WK_0_or_1=$((${WEEKNO} % 2))
if [[ ${WK_O_or_1} -eq 0 ]]
then
echo "Do your thing"
else
exit 0 # don't do nothing
fi
The ($(caljd.sh) + 1) makes each week start on a Sunday.
Now the next one is a little more tricky but we can even expand on your baby-food definition of a workday to exclude real honest-to_God holidays as well as weekends.
Create/update your /etc/acct/holidays file to reflect reality. (You should already have a default and very old version on your box). Caljd.sh actually looks for /etc/acct/holidays_2004 BEFORE it looks for the default /etc/acct/holidays so that this stuff even will work across year boundaries and observe holidays. You should really create a soft-link between holidays_YYYY and holidays for the current year.
Now create a cron entry to run every Monday through Friday; this is overkill but I have no idea how many holidays you have and this won't hurt.
15 9 * * 1-5 /usr/local/bin/myscript2.sh
#!/usr/bin/sh
PATH=${PATH}:/usr/local/bin
export PATH
typeset -i TODAYS_MONTH=$(caljd.sh -M)
typeset -i PREV_MONTH_MAYBE=$(caljd.sh -p 1 -x 0 -x 6 -h -M)
if [[ ${TODAYS_MONTH} -ne ${PREV_MONTH_MAYBE} ]]
then
echo "First working day of the month; do your thing"
else
exit 0
fi
The -p 1 says previos day; -x 0 skip Sundays; -x 6 ditto Saturdays; -h skip holidays (as defined in /etc/acct/holidays_YYYY). -M output just the month. Basically if today's month ain't equal to yesterday's month (skipping in the same direction weekends and holidays) then it's the first working day of the month.
I'm assuming you install the attached caljd.sh, in /usr/local/bin. Invoke as caljd.sh -u for full usage and examples.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2004 10:47 AM
11-05-2004 10:47 AM
Re: Cron Question/Suggestion.
1. If the date ( date +%d) is 1, then run only if the day (date +%a) is neither Saturdy nor Sunday.
2. If the date is 2, then run it only if it is monday.
3. If the date is 3, then run it only if it is monday.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2004 10:49 AM
11-05-2004 10:49 AM
Re: Cron Question/Suggestion.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2004 11:03 AM
11-05-2004 11:03 AM
Re: Cron Question/Suggestion.
#!/usr/bin/sh
PATH=${PATH}:/usr/local/bin
export PATH
typeset -i TODAY=$(caljd.sh)
itypeset -i TODAY_HOLIDAY_MAYBE=$(caljd.sh -h) # skip is positive if neither -p days or -n days is specified
if [[ ${TODAY} -ne ${TODAY_HOLIDAY_MAYBE} ]]
then
exit 0 # today's a holiday
fi
typeset -i TODAYS_MONTH=$(caljd.sh -M)
typeset -i PREV_MONTH_MAYBE=$(caljd.sh -p 1 -x 0 -x 6 -h -M)
if [[ ${TODAYS_MONTH} -ne ${PREV_MONTH_MAYBE} ]]
then
echo "First working day of the month; do your thing"
else
exit 0
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2004 11:15 AM
11-05-2004 11:15 AM
Re: Cron Question/Suggestion.
Great Answers.
Just wanted to know if my answers would work or anything wrong with that?
Thanks
Brian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2004 11:22 AM
11-05-2004 11:22 AM
Re: Cron Question/Suggestion.
I imagine you would keep some kind of error checking in your script for failures? Because you are going to add some logic anyway, it doesn't take long adding couple of lines that will either page you or send you a mail so you can fix things easily in which case 'at' doesn't hurt you. Even you can add a 'trap' inside that can automatically 'at' the job in case of any failures. You can also put some logic with week numbers given by 'date' for case 2. But you already got a cooked script/program so it's just a food for thought.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2004 11:27 AM
11-05-2004 11:27 AM
Re: Cron Question/Suggestion.
Thanks. i have never used at. If i have to use "at" then could you give me the commands for my question?
Thanks Again,
Brian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2004 11:29 AM
11-05-2004 11:29 AM
Re: Cron Question/Suggestion.
I kept clicking submit and finally I could post the last message. Regarding your answers -
1. I don't think "" is a valid cron entry. ;-).
2. Taking only Sat-Sun as holidays, you don't need to run the script everyday from 1st to 7th.
I believe you already got a working solution in hand so you don't have to work hard unless you want to devise one yourself.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2004 11:39 AM
11-05-2004 11:39 AM
Re: Cron Question/Suggestion.
'man at' gives you what you need. To schedule a job after 14 days or 2 weeks run
at now + 2 weeks < your_job
To list your at jobs
at -l
An example to use 'trap' in case of any failures.
schedule()
{
at now + 2 weeks < your_job > /tmp/log$$ 2>&1
mailx -s "at status" your_id@yourmail.com < /tmp/log$$
rm -f /tmp/log$$
}
trap schedule 0 1 2 3 4
Put the above before the contents of your script
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2004 11:40 AM
11-05-2004 11:40 AM
Re: Cron Question/Suggestion.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2004 08:48 AM
11-11-2004 08:48 AM