Computing.Net > Forums > Unix > script to get the files created on recent sat

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

script to get the files created on recent sat

Reply to Message Icon

Name: sucharita
Date: July 6, 2009 at 23:37:20 Pacific
OS: Windows XP
Subcategory: General
Comment:

script to get the files created on recent saturday and sunday irrespective on the day on which we run



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: July 7, 2009 at 15:29:44 Pacific
Reply:


To be accurate, Unix does not have a file creation time - just a file modification time. The modification time is changed each time a file is written to. Any user with write permission on a file can change the modification file with the touch command.

The best you can hope for is a script showing the modification time of last Sat or Sun. Can you live with that?


0

Response Number 2
Name: sucharita
Date: July 8, 2009 at 02:43:20 Pacific
Reply:

I need a script for getting the list of files showing the modification time of last Sat or Sun.

please help me out


0

Response Number 3
Name: nails
Date: July 10, 2009 at 07:41:30 Pacific
Reply:

What you are asking for is not easy. You have to subtract backward thru the days until you hit Sunday and Saturday thus endding the loop.

Also, there are special condtions for the end of the month and end of the year. I didn't test them and I am leaving the leap year check to you::

#!/bin/ksh

typeset -i mnum

get_month_no()
{
   case $1 in
      "Jan") echo "1";;
      "Feb") echo "2";;
      "Mar") echo "3";;
      "Apr") echo "4";;
      "May") echo "5";;
      "Jun") echo "6";;
      "Jul") echo "7";;
      "Aug") echo "8";;
      "Sep") echo "9";;
      "Oct") echo "10";;
      "Nov") echo "11";;
      "Dec") echo "12";;
      *) echo "error";;
esac
}

# This function returns the day of week where
# 0 = sunday, 1 = monday, ... 6 = saturday
# This algorithm is from Mike Keith's World of Words & Numbers:
# <a href="http://users.aol.com/s6sj7gt/mikecal.htm" target="_blank">http://users.aol.com/s6sj7gt/mikeca...</a>
# arguments: $1 = month, $2 = day, $3 = year in format YYYY
get_dow()
{
# [.] means to truncate downward to the nearest integer
# dayofweek=([23m/9] + d + 4 + y + [z/4] - [z/100] + [z/400] - 2 (if m >= 3)) mod 7
typeset -i DOW
typeset -i z
typeset -i multpr

if [ $1 -lt 3 ]
then # year determination
   z=$(($3-1))
else
   z=$3
fi
if [ $1 -ge 3 ]
then # set the multiplier
   multpr=2
else
   multpr=0
fi
DOW=$(( ((23 * $1/9) + $2 + 4 + $3 + ($z/4) - ($z/100) + ($z/400) - $multpr) % 7))

echo $DOW
}

mnum=$(date '+%m')
day=$(date '+%d')
year=$(date '+%Y')

sat_day=0
sun_day=0
# find the previous saturday
while true
do
   dow_num=$(get_dow $mnum $day $year)
   if [[ $dow_num = 0 ]]
   then # sunday
     sun_day=$day
   fi
   if [[ $dow_num = 6 ]]
   then # quit if it's saturday
      sat_day=$day
      break
   fi
   ((day-=1))
   if [[ $day = 0 ]]
   then # previous month UNTESTED
      ((mnum-=1))
      if [[ $mnum = 0 ]]
      then # Jan, UNTESTED
         mnum=12
         ((year-=1))
         day=31
      else
         case "$mnum" in
            9,4,6,11) day=30;;
            1,3,5,7,8,9,10) day=31;;
            2) day=28;; # NO LEAP YEAR CHECK
         esac
      fi
   fi
done

#   echo "Sat is: $sat_day "
#   echo "Sun is: $sun_day"

ls -l |while read f1 f2 f3 f4 f5 fmon fday f8 f9
do
  nm=$(get_month_no $fmon)

   if [[ ($nm = $mnum) && ($sat_day = $fday) ]]
   then
      echo "File $f9 is on saturday, $sat_day"
   fi

   if [[ ($nm = $mnum) && ($sun_day = $fday) ]]
   then
      echo "File $f9 is on sunday, $sun_day"
   fi
done


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: script to get the files created on recent sat

Shell script to get the files by range www.computing.net/answers/unix/shell-script-to-get-the-files-by-range/8413.html

shell script to find & get the specific file www.computing.net/answers/unix/shell-script-to-find-get-the-specific-file/8415.html

ftp script issue www.computing.net/answers/unix/ftp-script-issue/6675.html