- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Cron help
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
Discussions
Discussions
Discussions
Forums
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
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
тАО02-01-2010 08:10 AM
тАО02-01-2010 08:10 AM
Cron help
The script needs to run 2/5/10 and next run should be 2/19/10
Thanks for any help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-01-2010 08:30 AM
тАО02-01-2010 08:30 AM
Re: Cron help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-01-2010 09:07 AM
тАО02-01-2010 09:07 AM
Re: Cron help
You want to use the modulus operator and check the remainder when divided by 2. There are only two results, 0 or 1. The SUMS stored are integers increasing by one every week. So the operation is 1/2, 2/2, 3/2, 4/2, 5/2, etc.
This becomes a boolean flag for you to trap on. Only trick is to save the last SUM in an file, which becomes an important part of the algorithm.
Here is Midnight every other Friday
weekday
The day of the week, 0-6, 0=Sunday
minute hour monthday month weekday FLAG command
00 00 * * 5 /dir/script
####################
script
#####################
/home/your_dir/FLAG filename.
FLAG=$((cat FLAG_FILE))
echo $FLAG
1
mymodulus=$(( $FLAG % 2 ))
1=1%2
case $FLAG in
"0") Execute script;;
"1") ;;
FLAG=$(($FLAG+1))
echo $FLAG
2
echo $FLAG>FLAG_FILE
##################################
Next time
##################################
/home/your_dir/FLAG filename.
FLAG=$((cat FLAG_FILE))
echo $FLAG
2
mymodulus=$(( $FLAG % 2 ))
0=2%2
case $FLAG in
"0") Execute script;;
"1") ;;
FLAG=$(($FLAG+1))
echo $FLAG
3
echo $FLAG>FLAG_FILE
##################################
Next time
##################################
/home/your_dir/FLAG filename.
FLAG=$((cat FLAG_FILE))
echo $FLAG
3
mymodulus=$(( $FLAG % 2 ))
1=3%2
case $FLAG in
"0") Execute script;;
"1") ;;
FLAG=$(($FLAG+1))
echo $FLAG
4
echo $FLAG>FLAG_FILE
Etc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-01-2010 10:57 AM
тАО02-01-2010 10:57 AM
Re: Cron help
> file and exits. [...]
Of course, if someone deletes the file, then
you can get the wrong result with no way to
detect the problem. You can also do things
like store a number (say, 0 or 1) in a file,
and look at that value instead of simply
testing the existence of the file.
bash$ echo 0 > flag_file
bash$ var=` cat flag_file `
bash$ var=` expr 1 - $var `
bash$ echo $var
1
bash$ echo $var > flag_file
bash$ var=` cat flag_file `
bash$ var=` expr 1 - $var `
bash$ echo $var
0
bash$ echo $var > flag_file
bash$ var=` cat flag_file `
bash$ var=` expr 1 - $var `
bash$ echo $var
1
bash$ echo $var > flag_file
[...]
Modern shells can do the math without using
"expr", and I didn't show a test for valid
file contents, but, as usual, many things are
possible.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-01-2010 11:28 AM
тАО02-01-2010 11:28 AM
Re: Cron help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-01-2010 12:17 PM
тАО02-01-2010 12:17 PM
Re: Cron help
will this work?
00 08 1-7,15-21 * 3 /home/oracle/test.sh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-01-2010 12:33 PM
тАО02-01-2010 12:33 PM
Re: Cron help
Do all months have exactly 28 days?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-02-2010 03:50 AM
тАО02-02-2010 03:50 AM
Re: Cron help
if (( $(date +%j) / 7 % 2 == 0)); then
echo Even
else
echo Odd
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-02-2010 04:12 AM
тАО02-02-2010 04:12 AM
Re: Cron help
if you can't handle this in ONE cron job, you can definetly do that by using more than one cron jobs-entries.
is'nt it simple :)
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-02-2010 05:10 AM
тАО02-02-2010 05:10 AM
Re: Cron help
Oh I see. You fill it up with 25/26 entries and change it each year. :-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-02-2010 06:38 AM
тАО02-02-2010 06:38 AM
Re: Cron help
>>00 08 1-7,15-21 * 3 /home/oracle/test.sh
No, I don't think this will do what you want. This job will run on the 1-7, the 15-21 AND on Friday. The job will run IF ANY of the last 3 fields are true.
Note the example from the cron man page:
Note that the specification of days can be made in two fields: monthday and weekday. If both are specified in an entry, they are cumulative. For example,
0 0 1,15 * 1 command
runs command at midnight on the first and fifteenth of each month, as well as every Monday.
>>Do all months have exactly 28 days?
Well, yes they do! ;)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-02-2010 06:45 AM
тАО02-02-2010 06:45 AM
Re: Cron help
> Well, yes they do! ;)
This must be some new meaning for the word
"exactly" (which I used for a reason).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-03-2010 07:45 AM
тАО02-03-2010 07:45 AM
Re: Cron help
Thanks for everyone contributed.
Here is the logic, if anyone needs it.
This will run biweekly sunday at 10.00am.
My cron
--------
00 10 * * 6 /myscript
My script
---------
#! /usr/bin/bash
if [ -e /tmp/fchek ] ; then
rm -f /tmp/fchek
else
touch /tmp/fchek
exit 0
fi
sh /myscript
exit 0
Explanation : (Not for experts!)
-------------
Script will look for a file /tmp/fcheck on the first run, it wont find it and it will create and exit. On the next week it will find the file, remove it and execute my script. On third week it wont find my file, create it and exit and so on....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-03-2010 07:46 AM
тАО02-03-2010 07:46 AM
Re: Cron help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-03-2010 08:11 AM
тАО02-03-2010 08:11 AM
Re: Cron help
> else
If someone changes the permissions on this
file, then the "rm" could fail (silently).
Of course, this should never happen. How
important is it that this job run exactly
every two weeks? Sometimes the easy way is
good enough. Sometimes it's not. You get to
decide what's good enough.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-03-2010 08:18 AM
тАО02-03-2010 08:18 AM