30 days oldfiles: Urgent


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting 30 days oldfiles: Urgent
# 8  
Old 03-02-2009
You need to:
- find all files older than 30 days?
- sort them from the oldest to newest?
- what do you want to do with the list of files?
# 9  
Old 03-02-2009
Almost working
#!/usr/bin/ksh
for i in 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31;
do

#######
DAYS_AGO=$i
DAY=`date +%d`
LMONTH=`date +%b`
MONTH=`date +%m`
YEAR=`date +%Y`
DAY_1=`expr "$DAY" - $DAYS_AGO`
echo $DAY_1
if [ $DAYS_AGO -ge $DAY ];then
MONTH=`expr "$MONTH" - 1`
case "$MONTH" in
0) MONTH=12;YEAR=`expr "$YEAR" - 1` ;;
esac
DAY_2=`cal $MONTH $YEAR | grep . | fmt -1 | tail -1`
DAY_Diff=`expr $DAYS_AGO - $DAY`
REAL_DATE=`expr $DAY_2 - $DAY_Diff`
if [ $REAL_DATE = 0 ] ; then
MONTH=`expr $MONTH - 1`
DAY=`cal $MONTH $YEAR | grep . | fmt -1 | tail -1`
fi
else
if [ $DAYS_AGO -lt $DAY ];then
MONTH=$MONTH
REAL_DATE=`expr $DAY - $DAYS_AGO`
fi
fi
DAY=$REAL_DATE

MONTH_LEN=`echo $MONTH|wc -c`
echo $MONTH_LEN
if [ $MONTH_LEN -eq 2 ]; then
MONTH="0$MONTH"
fi
DAY_LEN=`echo $DAY|wc -c`
echo $DAY_LEN
if [ $DAY_LEN -eq 2 ]; then
DAY="0$DAY"
fi
case $MONTH in # set month name
01) LMONTH="Jan";;
02) LMONTH="Feb";;
03) LMONTH="Mar";;
04) LMONTH="Apr";;
05) LMONTH="May";;
06) LMONTH="Jun";;
07) LMONTH="Jul";;
08) LMONTH="Aug";;
09) LMONTH="Sep";;
10) LMONTH="Oct";;
11) LMONTH="Nov";;
12) LMONTH="Dec";;
esac
echo "$YEAR/$MONTH/$DAY"

############
done
# 10  
Old 03-02-2009
First of all plz check below command for older than 30 day file exist or not

find . -type f -mtime +30 > File30DaysOlder (. replace with want dir)

Second Plz check file create in tmp directory..

Please let me know.

Regards,
Div
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to find a file that's modified more than 2 days ago but less than 5 days ago?

How to find a file that's modified more than 2 days ago but was modified less than 5 days ago by use of any Linux utility ? (4 Replies)
Discussion started by: abdulbadii
4 Replies

2. Shell Programming and Scripting

URGENT Reading a file and assessing the syntax shell script URGENT

I am trying to write a shell script which takes an input file as an arguement in the terminal e.g. bash shellscriptname.sh input.txt. I would like for the file to be read line by line each time checking if the .txt file contains certain words or letters(validating the syntax). If the line being... (1 Reply)
Discussion started by: Gurdza32
1 Replies

3. Shell Programming and Scripting

Working out days of the week and processing file in 3 working days

Hi guys i need advice on the approach to this one...... I have a file say called Thisfile.20130524.txt i need to work out from the date 20130524 what day of the week that was and then process the file in 3 working days. (so not counting saturday or sunday....(will not worry about bank... (2 Replies)
Discussion started by: twinion
2 Replies

4. Shell Programming and Scripting

Cron job running for some days and is not running for some days

Hi.. i have written a shell script and made this script to run on every day night 11: 55 pm using a cron job. This cron job running for some days and is not running for some day. but i need this script to run every day night. Please help me. Here is the cron tab entries, 55 23 * * *... (1 Reply)
Discussion started by: vidhyaS
1 Replies

5. Shell Programming and Scripting

before x days

hello, I needed to put value of date - 20 days in certain variable like this: before20d=`TZ=MET+480 date +%Y%m%d` echo $before20d value just perfect ...what I need and if I execute "date": Wed Nov 10 11:58:43 MET 2010 on the other solaris platform if I execute this I get... (4 Replies)
Discussion started by: abdulaziz
4 Replies

6. Shell Programming and Scripting

date for two days or 3 days ago

i need a script that can tell me the date 2 days ago or 3 days ago. please help (7 Replies)
Discussion started by: tomjones
7 Replies

7. Shell Programming and Scripting

ls latest 4 days or specify days of files in the directory

Hi, I would like to list latest 2 days, 3 days or 4 days,etc of files in the directory... how? is it using ls? (3 Replies)
Discussion started by: happyv
3 Replies

8. UNIX for Advanced & Expert Users

URGENT,URGENT- Need help tape drive installation

Hi, I am trying to attach tape drive to sun V890 running Solaris 9 on it. I have installed HBA(qlogic) in slot 1 of 0-8 slots and booted the system. I do not see HBAin prtdiag output. The tape drive is not attached to HBA. The tape drive I am going to attach is Sony AIT3. 1.How can I make... (3 Replies)
Discussion started by: sriny
3 Replies
Login or Register to Ask a Question