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
find files modified in a specific month omer_ome UNIX for Advanced & Expert Users 1 07-02-2006 06:43 AM
find files modified in a specific month omer_ome SUN Solaris 1 07-02-2006 06:38 AM
find files modified in a specific month omer_ome HP-UX 1 07-02-2006 06:36 AM
How to get previous month files savitha Shell Programming and Scripting 7 03-23-2006 02:16 AM
Find all files by month maldini Shell Programming and Scripting 13 08-02-2005 10:22 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 04-25-2006
Registered User
 

Join Date: Apr 2006
Posts: 7
backup files for a specific month

i am having a problem with writing a shell script to back up files for a specific month. the month and year are specified as paramters. so a backup of all the files modified during the specified month have to be made. for example if specify 200406 as my parameter, it should back up files that have been modified during the month of june in year 2004

i know u can use the find -atime -n. but it aonly finds files that were accesed within n days. but i would like to find files for a specific month and back it up. need help please

thanks
Reply With Quote
Forum Sponsor
  #2  
Old 04-26-2006
Registered User
 

Join Date: Mar 2006
Location: Gurgaon
Posts: 26
I think u will need to find the diff of current that with the start and end date of the month u want backup.
and u may use the find . -mtime -60 -mtime +30
-mtime -60,...less than 60 days ago
-mtime +30...more than 30 days ago..
this way u will have to look for yours month duration...
but there should be better ways...may be someone else in group can help
Reply With Quote
  #3  
Old 04-27-2006
Registered User
 

Join Date: Mar 2006
Location: South Yorkshire, UK
Posts: 114
An alternative is to try to match the Month and year in a directory listing - tho the change from "dd Mmm hh:mm" format to "dd Mmm yyyy" when a file gets to six months old complicates this.
I would be a good idea to log the details of files deleted too!

Code:
Code
# note proper parameter validation (e.g. mon between 1 and 12 inclusive)
# script also assumes that you have read/write access to all subdirectories

scriptname=$(basename $0)
if [ $# -ne 3 ]; then
  print "usage: $scriptname MonthNumber YearNumber directory, e.g. '$scriptname 4 2006 /tmp'"
  exit 0
fi

set -A monnames Zero Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
typeset -i mon=$1
typeset -i yr=$2
typeset -i thisyr=$(date +%Y)
typeset -i lastyr=$(($thisyr -1))
typeset -i thismon=$(date +%m)
typeset -i fmon

print "Print Deleting files from ${monnames[$mon]} $yr in directory $3"

find $3 -type f -ls | sed -e's/ *//' | tr -s ' ' | cut -d' ' -f8- | while read fmonname fday fyrtime ffilename
do

# Get month number from month name in file list
  fmon=1
  while :
  do
    if [ $fmonname = ${monnames[$fmon]} ]; then
      break
    fi
    fmon=$(($fmon + 1))
  done

# if the last part of the timestamp is a time rather than a yr then
# we need to find the yr it belongs to

  if [[ $fyrtime = *:* ]]; then

#   if month number is not greater than current month number then it is in this yr ...
    if [ $fmon -le $thismon ]; then
      fyrtime=$thisyr
    else

#     ... otherwise it's last yr
      fyrtime=$lastyr
    fi
  fi

  if [ $fmon = $mon ]&&[ $fyrtime = $yr ]; then
    print "deleting $fname dated $fday $fmon $fyrtime $ffilename"
    -- backup $ffilename somehow --
  fi
done
~
any help?

cheers

Last edited by thestevew; 04-28-2006 at 03:26 AM.
Reply With Quote
  #4  
Old 04-28-2006
Registered User
 

Join Date: Apr 2006
Posts: 7
thanks but i wanted to copy the files for a specilfy month. is it possible to search through the directory list for the specific month specified
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:19 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