Find info based on date

Reply

Join Date: Feb 2006
Posts: 17
Reputation: rusman is an unknown quantity at this point 
Solved Threads: 0
rusman rusman is offline Offline
Newbie Poster

Find info based on date

 
0
  #1
Apr 30th, 2007
Hello everyone,

Given a list of output that looks like this (from NetBackup bpimagelist if any of you are familiar), I need to pick out the last full backup closest to the end of the quarter (3/30, 6/30, 9/30 12/31).

10/20/2006 21:24 INFINITY 146144 64213523 N Full Backup
10/13/2006 21:46 INFINITY 144120 60868157 N Full Backup
10/06/2006 21:22 INFINITY 148940 59931237 N Full Backup
09/23/2006 02:14 INFINITY 114239 57878059 N Full Backup
09/15/2006 21:31 INFINITY 137821 58463789 N Full Backup
09/01/2006 23:47 INFINITY 130842 57890925 N Full Backup
08/25/2006 21:34 INFINITY 120475 57706942 N Full Backup
08/11/2006 22:49 INFINITY 105830 54603266 N Full Backup
06/28/2006 23:37 INFINITY 110950 45103754 N Full Backup

In the example above, I would want to pull out the 6/28 and 9/23 backups.

I appreciate any help!
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 178
Reputation: jim mcnamara is on a distinguished road 
Solved Threads: 10
jim mcnamara jim mcnamara is offline Offline
Junior Poster

Re: Find info based on date

 
0
  #2
May 8th, 2007
try:
Shell Scripting Syntax (Toggle Plain Text)
  1. #!/bin/ksh
  2.  
  3. export infile=filename
  4. filedate()
  5. {
  6. perl -e '
  7. use Time::Local;
  8. $mytime = timelocal(0,$ARGV[4],$ARGV[3],$ARGV[1],
  9. $ARGV[0] - 1,$ARGV[2] - 1900);
  10. print "$mytime\n";
  11. ' $1 $2 $3 $4 $5
  12. }
  13.  
  14.  
  15. compare()
  16. {
  17. keep="None found"
  18. maxallowed=$1
  19. minallowed=$2
  20. result=$minallowed
  21. while read record
  22. do
  23. echo "$record" | tr -s '/' ' ' | tr -s ':' ' '| \
  24. read mon day yr hr mins dummy
  25. filedate $mon $day $yr $hr $mins | read value
  26. if [[ $value -lt $minallowed || $value -gt $maxallowed ]] ; then
  27. continue
  28. fi
  29. if [[ $value -gt $result ]] ; then
  30. result=$value
  31. keep=$record
  32. fi
  33. done < $infile
  34. print "$keep"
  35. }
  36.  
  37. # Q1
  38. filedate 12 31 2005 23 59 | read min
  39. let min=$min+61
  40. filedate 03 30 2006 23 59 | read limit
  41. compare $limit $min
  42.  
  43. #q2
  44. let min=$limit+61
  45. filedate 06 30 2006 23 59 | read limit
  46. compare $limit $min
  47.  
  48. #q3
  49. let min=$limit+61
  50. filedate 09 30 2006 23 59 | read limit
  51. compare $limit $min
  52.  
  53. #q4
  54. let min=$limit+61
  55. filedate 12 31 2006 23 59 | read limit
  56. compare $limit $min

input file:
Shell Scripting Syntax (Toggle Plain Text)
  1. 10/20/2006 21:24 INFINITY 146144 64213523 N Full Backup
  2. 10/13/2006 21:46 INFINITY 144120 60868157 N Full Backup
  3. 10/06/2006 21:22 INFINITY 148940 59931237 N Full Backup
  4. 09/23/2006 02:14 INFINITY 114239 57878059 N Full Backup
  5. 09/15/2006 21:31 INFINITY 137821 58463789 N Full Backup
  6. 09/01/2006 23:47 INFINITY 130842 57890925 N Full Backup
  7. 08/25/2006 21:34 INFINITY 120475 57706942 N Full Backup
  8. 08/11/2006 22:49 INFINITY 105830 54603266 N Full Backup
  9. 06/28/2006 23:37 INFINITY 110950 45103754 N Full Backup
output:
Shell Scripting Syntax (Toggle Plain Text)
  1. kcsdev:/home/jmcnama> closest.sh
  2. None found
  3. 06/28/2006 23:37 INFINITY 110950 45103754 N Full Backup
  4. 09/23/2006 02:14 INFINITY 114239 57878059 N Full Backup
  5. 10/20/2006 21:24 INFINITY 146144 64213523 N Full Backup
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Shell Scripting Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC