The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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 02:46 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-13-2008
ali560045's Avatar
ali560045 ali560045 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 328
need help in crontab

I have a script called nav1.sh. How to crontab this script so that it runs every 15 days. Below the Crontab option availaible in my Unix AIx version.Let's say for example if my script rans on 13th Oct then it again after 15 days it should ran i.e on 28th Oct and so on .


Min(0-59) Hour(0-23) DayofMonth(1-31) Month(1-12) DayofWeek(0-6, Sun=0)

Last edited by ali560045; 10-13-2008 at 01:30 AM..
  #2 (permalink)  
Old 10-13-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
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 02:19 AM.. Reason: Removed duplicate calculation of modulus.
  #3 (permalink)  
Old 10-13-2008
ali560045's Avatar
ali560045 ali560045 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 328
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
  #4 (permalink)  
Old 10-13-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
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

...

  #5 (permalink)  
Old 10-13-2008
ali560045's Avatar
ali560045 ali560045 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 328
but u missed the else part shall it be like this


#!/bin/ksh

days_since_epoch=$(perl -e 'print int(time/86400);')

if [[ "$(( $days_since_epoch % 15 ))" -ne 5 ]]
then
exit
else
my script
fi
  #6 (permalink)  
Old 10-13-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
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.
  #7 (permalink)  
Old 10-13-2008
ali560045's Avatar
ali560045 ali560045 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 328
thanks a lot. got the logic and again thank you so much
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:58 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0