![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| crontab couldn't run through, help | duke0001 | UNIX for Advanced & Expert Users | 10 | 02-06-2008 03:22 AM |
| Using Crontab | sumesh.abraham | Shell Programming and Scripting | 10 | 02-21-2007 06:19 AM |
| crontab | ss4u | UNIX for Dummies Questions & Answers | 2 | 02-20-2007 10:33 AM |
| help with crontab | bob122480 | Shell Programming and Scripting | 3 | 01-22-2007 08:49 PM |
| Need help in crontab? | J_ang | Shell Programming and Scripting | 3 | 07-22-2006 01:46 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Unfortunately cron isn't very flexible in that respect. Does your script need to run exactly every 15 days, or could you just run it on the 1st and 16th of every month, i.e. approximately every 15 days?
Otherwise you might have to just run the job every day, and add some logic so that it exits without doing anything if the current number of days since Jan 1, 1970 is not evenly divisible by 15: Code:
days_since_epoch=$(perl -e 'print int(time/86400)"\n";')
if [[ "$(( $days_since_epoch % 15 ))" -ne 0 ]]
then
exit
else
# do your stuff
fi
Last edited by Annihilannic; 10-13-2008 at 01:19 AM.. Reason: Removed duplicate calculation of modulus. |
|
|||||
|
yes script has to run every 15days. if it rans today i.e. 13th oct, next would be on 28th oct and again 0n 13th nov.
I have below given the script details,can u tell me how to implement this date logic inside my script ------------------------------------------------------------------------- #!/bin/ksh cd /var/preserve count=0 count=`ls -ltr | grep ^- | grep 'pipe' | wc -l` if [ $count -eq 0 ] then echo "0 Files are owned by pipe" else echo "total files owned by pipe is $count" ls -ltr | grep 'pipe' | xargs rm -f - echo "All pipe files are deleted" fi ------------------------------------------------------------------------- i know of a command that will give the date after 15days, but not getting the logic to implement it inside the script TZ=`date +%Z`-360 ;a=`date +%Y-%m-%d`--------> 2008-10-28 |
|
||||
|
Just change the beginning like this. Today is 14165 days since the epoch, and 14165 % 15 = 5. That means this script will run today, and in 15 days time, 30 days, 45, etc.
Code:
#!/bin/ksh
days_since_epoch=$(perl -e 'print int(time/86400);')
if [[ "$(( $days_since_epoch % 15 ))" -ne 5 ]]
then
exit
fi
...
|
|
||||
|
Think about it... there's no real need for the else part... if it's not the day you want, it will exit... if it *is* the day you want, the script will just continue on and execute the rest of your code.
You could put it in an else clause if you wish, but the result is the same. |