- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Cronjob every 10 days?
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
05-02-2002 07:52 AM
05-02-2002 07:52 AM
I need to transmit some data files every 10 days at midnite. At the present, I have a crontab entry that runs my transfer script every day and then tests the date '+%j'. If that modulo 10 value is correct, the script executes otherwise it exits without doing any transfers. I am concerned that this may not work when I jump to a new year. Am I on the right track or can I do this with cron alone? Any help would be appreciated.
TIA, Bob
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2002 07:57 AM
05-02-2002 07:57 AM
Re: Cronjob every 10 days?
You are - I think - on the right track. I would - if I were you - use the caldate.sh script from Clay - which you'll find everywhere in the forums :-) to convert the date ... and then do the modulo 10. That way you'll be sure about the year-leaps as well.
Regards,
Tom
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2002 08:00 AM
05-02-2002 08:00 AM
Re: Cronjob every 10 days?
This is one that cron can definitely NOT do.
You should take a look at Clay Stephenson's calendar program.
Search the forum for "calendar program".
Rgds,
Jeff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2002 08:00 AM
05-02-2002 08:00 AM
Re: Cronjob every 10 days?
Another useful method is to use 'at' (see the man pages). When your task runs, the last thing it does is re-schedule itself:
# at -f $HOME/mything now +10 days
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2002 08:01 AM
05-02-2002 08:01 AM
SolutionYou are very close; you just need a better counter of days. You are the lucky winner - I recently finished my upgrade to caljd.sh - caljd.pl. It runs much faster but the commands/options are exactly the same. Your script should do something like this:
PATH=${PATH}:/usr/local/bin
export PATH
OFFSET=0
if [ $(( $(caljd.pl) + ${OFFSET}) % 10)) -eq 0 ]
then
echo "Execute your stuff"
else
echo "Do Nothing"
fi
You will need to play with the value of OFFSET (0-9) depending on which day you wish to start the cycle. You should install caljd.pl in /usr/local/bin. Caljd.pl -u gives full usage. You can also search the Forums for caljd.sh, if you like and use it instead. Vrsn 2.05 is the latest.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2002 08:01 AM
05-02-2002 08:01 AM
Re: Cronjob every 10 days?
I like your logic. It should work except that it will not run on 4th of Jan which is 10days away from 360th day of the previous year. It will start from 10th day next year onwards.
My script would invoke an atjob to run it again after 10days using + 10 days option. Look at atjob man page.
There is also one nice utility caljd.sh posted by Clay that can be used to achive this. Search this site using caljd.sh string.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2002 08:02 AM
05-02-2002 08:02 AM
Re: Cronjob every 10 days?
Merely by using the julian date, it doesn't matter if it is a leap year or not. The problem will always be at the end of the year.
Non-leap year:
360 = transmit
365 = end of year
Next year
010 = next date of transmit
360 = last transmit for year
next year (leap)
010 = next date of transmit
360 = last transmit for year
next year (non-leap)
010 = next date of transmit.
...
So, no matter if it is a leap year or not, you WILL have issues at the end of each year.
It will either be 15 days for a non-leap year or 16 days for a leap year.
You need a better way, unless it doesn't matter at the end of the year. May I suggest that you always send the next files at the end of the year no matter the date difference?
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2002 08:05 AM
05-02-2002 08:05 AM
Re: Cronjob every 10 days?
To keep the Perl purists (nutballs?) off my case, you could also do this:
perl -e 'use integer; exit(((time() / 86400) + 0) % 10);'
STAT=$?
if [ ${STAT} -eq 0 ]
then
echo "Do your stuff"
else
echo "Do nothing"
fi
THe + 0 should be in the range 0-9 and serves exactly the same purpose as ${OFFSET} in my prior example.
Regards, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2002 08:07 AM
05-02-2002 08:07 AM
Re: Cronjob every 10 days?
Go with JRF's at suggestion but at the end of $HOME/mything do this:
echo "$HOME/mything" | at now +10 days
This will put the same job right back into the at queue for 10 days hence.
Good luck,
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2002 08:12 AM
05-02-2002 08:12 AM
Re: Cronjob every 10 days?
Another way:-
Two cron jobs
First to run
echo "1" >> daycount.
Second
looks at day count and adds up the ones.
If equal to 10 then do then job if not dont.
If 10 then echo "1" > daycount (reset).
This will give no End of month/ year / leapyear problems.
HTH
Paula
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2002 08:22 AM
05-02-2002 08:22 AM
Re: Cronjob every 10 days?
If you are using modulo 0 for this year then I reckon that you'd need modulo 5 next year otherwise you'd have a 15 day interval from about 26th December to 10th January.
Here is a very simple C program that calculates the absolute day number since the UNIX epoch:-
#include
#include
main()
{
printf("%d\n",time(NULL)/86400);
}
------------------------------
You can extend that simply to provide you with that number of days modulo 10:
#include
#include
main()
{
time_t time_now;
int days;
int mod;
time_now=time(NULL);
days=time_now/86400;
mod=days%10;
printf("%d\n",mod);
}
------------------------------
Today is epoch modulo 9 whereas the Julian date is modulo 2 so you'd have to change your script to run the compiled program instead of date, then test for epoch modulo 7 instead of 0.
Regards,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2002 08:39 AM
05-02-2002 08:39 AM
Re: Cronjob every 10 days?
http://sourceforge.net/projects/anacron/
HTH,
Trever
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2002 10:15 AM
05-02-2002 10:15 AM
Re: Cronjob every 10 days?
Re-inventing, re-compiling, talk about overkill!! Just use at
at -f scriptname now +10 days
The last line in scriptname should be
echo "scriptname" |at now +10 days
Does exactly what you want. No fuss, no muss.
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2002 10:44 AM
05-02-2002 10:44 AM
Re: Cronjob every 10 days?
Clay, I downloaded your Perl version on my PC before transferring it to my HP-UX server. Just for fun, I ran it on my PC and it worked there too!!! I also liked the usage message in the Perl version. It is a little clearer than the caljd.sh version.
I feel stupid because I had already used your caljd.sh script on another project and I should have been able to think of this solution myself.
Thanks everybody for the hints.
Bob