computing go/no-go dates in script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting computing go/no-go dates in script
# 1  
Old 03-22-2006
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.
# 2  
Old 03-22-2006
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.
# 3  
Old 03-23-2006
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
# 4  
Old 03-23-2006
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script with Dates

Hi from Uruguay. Im having a problem with a scripts using dates, this is the problem: I have a folder for each day, like : 20160711 for yesterday, 20160712 for today, and i want to mv to a backup folder the folders who exceed the year of antiquity (365 days from today) and that script execute... (3 Replies)
Discussion started by: michipoput
3 Replies

2. Shell Programming and Scripting

Comparing dates in shell script

Hi All, I have a date variable say dt="2014-01-06 07:18:38" Now i need to use this variable to search a log and get the entries which occured after that time. (1 Reply)
Discussion started by: Girish19
1 Replies

3. Shell Programming and Scripting

Script to read a log file and run 2nd script if the dates match

# cat /tmp/checkdate.log SQL*Plus: Release 11.2.0.1.0 Production on Mon Sep 17 22:49:00 2012 Copyright (c) 1982, 2009, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production FIRST_TIME NEXT_TIME... (1 Reply)
Discussion started by: SarwalR
1 Replies

4. Shell Programming and Scripting

Computing the ratio of similar columns in the two files using awk script

Thanks Bartus11 for your help in the following code to compare the two files "t1" and "t2". awk 'NR==FNR{a=1;next}$2 in a{print $2}' t1 t2 First can anyone explain that what is the purpose of assigning a =1? Second, the current script is printing out the matched columns between the... (4 Replies)
Discussion started by: coder83
4 Replies

5. Shell Programming and Scripting

Need help with script changing dates

I am attempting to write a script where the user enters the month and day (two digit format). I am trying to have script will increase 6 more times (totaling 7). I am having issues with the script increasing by one (its either dropping off the lead zero or not increasing for 08 and 09). While... (8 Replies)
Discussion started by: bbraml
8 Replies

6. Shell Programming and Scripting

script with dates to gzip and remove

Good morning all! I am new to programming and trying to learn; please be patient. I am wanting to write a script that takes the current date and gzip 5 days or older, then remove 10 days or older. This is the directory I want to work in; this is what it looks like ... (2 Replies)
Discussion started by: bigben1220
2 Replies

7. Shell Programming and Scripting

Pause for remote computing in Telnet script

I am running a telnet script that connects to a database server and executes sql scripts. While the remote database is processing the commands within the sql scripts, my telnet script continues to send commands. Okay, that's fine. They get queued up in the remote server and executed sequentially.... (3 Replies)
Discussion started by: oldjuke
3 Replies

8. Shell Programming and Scripting

Need script to generate all the dates in DDMMYY format between 2 dates

Hello friends, I am looking for a script or method that can display all the dates between any 2 given dates. Input: Date 1 290109 Date 2 010209 Output: 300109 310109 Please help me. Thanks. :):confused: (2 Replies)
Discussion started by: frozensmilz
2 Replies

9. Shell Programming and Scripting

Help in automating dates in ksh script

I need to run a command at the end of a backup job and this command will produce a report of what my backup jobs have collected in the previous day. The real problem is that this binary works with absolute dates only, so I should have to modify the script every single time I need it to work. It... (1 Reply)
Discussion started by: italia1971luca
1 Replies

10. Virtualization and Cloud Computing

Event Cloud Computing - IBM Turning Data Centers Into ?Computing Cloud?

Tim Bass Thu, 15 Nov 2007 23:55:07 +0000 *I predict we may experience less*debates*on the use of the term “event cloud”*related to*CEP in the future, now that both IBM and Google* have made announcements about “cloud computing” and “computing cloud”, IBM Turning Data Centers Into ‘Computing... (0 Replies)
Discussion started by: Linux Bot
0 Replies
Login or Register to Ask a Question