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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help in automating dates in ksh script italia1971luca Shell Programming and Scripting 1 06-04-2008 03:29 AM
Event Cloud Computing - IBM Turning Data Centers Into ?Computing Cloud? iBot Complex Event Processing RSS News 0 11-15-2007 05:30 PM
How to compare the dates in shell script vaji Shell Programming and Scripting 9 02-27-2007 09:34 PM
Trusted Computing kduffin Security 0 06-15-2006 12:07 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 03-22-2006
Supporter
 

Join Date: Feb 2005
Posts: 49
computing go/no-go dates in script

I am working on a bash script to backup selected servers and am trying to come up with a simpler solution to this problem:

Each server to be backed up has a config file that is read by the script, in the config file are the following values:
LEVEL0=12 #this is the day of the month on which level zero backups are performed.
INTERVAL=3: #In this case every 3 days before or after the LEVEL0 date an interval backup will be performed.

The LEVEL0 and INTERVAL values will be different for different servers.

I could just write a loop to compute if the current day is a day on which to perform an interval backup but it seems that there must be a simpler way to calculate this.

If anyone can point me in the right direction I would appreciate it very much.
Reply With Quote
Forum Sponsor
  #2  
Old 03-22-2006
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,326
If I am not wrong, you just have to determine if the date is one on which an interval backup is to be taken. You could use something like this:
Code:
#!/usr/bin/ksh
d=$(date +%d)

if [ $(($LEVEL0 - $INTERVAL)) -eq $d -o $(($LEVEL0 + $INTERVAL)) -eq $d ]; then
#### take backup here
fi
This bit will just check that it is a day on which you take the intermediate backup. For a level 0 backup, you can just check if the day of the month is the same as the LEVEL0 value.
Reply With Quote
  #3  
Old 03-23-2006
Registered User
 

Join Date: Mar 2006
Location: South Yorkshire, UK
Posts: 114
If you need an interval backup on every INTERVAL days before and after the full backup date then how about using a modulus from the full day number:

Code:
LEVEL0=12   ;# read these value from ...
INTERVAL=3 ;# ... parameter file

d=$(date +%d)

if [ $LEVEL0 -eq $d ]; then
    print backup is Full on day $d           ;# replace by doing something useful here ...
else
  if [ $(( ($d - $LEVEL0) % $INTERVAL)) -eq 0 ]; then
    print backup is Interval on day $d     ;# ... and here
  fi
fi
cheers
Reply With Quote
  #4  
Old 03-23-2006
Supporter
 

Join Date: Feb 2005
Posts: 49
Quote:
Originally Posted by blowtorch
If I am not wrong, you just have to determine if the date is one on which an interval backup is to be taken. You could use something like this:
Code:
#!/usr/bin/ksh
d=$(date +%d)

if [ $(($LEVEL0 - $INTERVAL)) -eq $d -o $(($LEVEL0 + $INTERVAL)) -eq $d ]; then
#### take backup here
fi
This bit will just check that it is a day on which you take the intermediate backup. For a level 0 backup, you can just check if the day of the month is the same as the LEVEL0 value.
blowtorch Thanks. That solved the problem. I knew that there had to be a more elegant solution than what I was using. Tested the code against about 30 date/interval settings and it works as needed.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:41 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0