The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 09:43 AM
find files modified in a specific month omer_ome SUN Solaris 1 07-02-2006 09:38 AM
find files modified in a specific month omer_ome HP-UX 1 07-02-2006 09:36 AM
How to get previous month files savitha Shell Programming and Scripting 7 03-23-2006 05:16 AM
Find all files by month maldini Shell Programming and Scripting 13 08-03-2005 01:22 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-25-2006
problems problems is offline
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
  #2 (permalink)  
Old 04-26-2006
JunkYardWars JunkYardWars is offline
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
  #3 (permalink)  
Old 04-27-2006
thestevew thestevew is offline
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 06:26 AM..
  #4 (permalink)  
Old 04-28-2006
problems problems is offline
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:55 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0