943,987 Members | Top Members by Rank

Ad:
Apr 30th, 2007
0

Find info based on date

Expand Post »
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!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rusman is offline Offline
17 posts
since Feb 2006
May 8th, 2007
0

Re: Find info based on date

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
Reputation Points: 62
Solved Threads: 10
Junior Poster
jim mcnamara is offline Offline
179 posts
since May 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: checking input
Next Thread in Shell Scripting Forum Timeline: Is recursion possible with strings command from command line?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC