Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

Files Not Being Listed

Original Message
Name: LiteBright
Date: December 14, 2006 at 08:23:36 Pacific
Subject: Files Not Being Listed
OS: UNIX
CPU/Ram: p4 4g
Model/Manufacturer: intel
Comment:
I have the following script that is suppose to list files with a certain date string contained in the name of the file. The script won't list any of the files, even though they are there.

typeset -Z2 KEEPDAYS=$((`date +%d` -7))
MONTH=`date +%m`
YEAR=`date +%Y`

if [ $KEEPDAYS -le "0" ] ; then
MONTH=$((MONTH-1))
if [ $MONTH -eq "0" ] ; then
MONTH=12
YEAR=$((YEAR-1))
fi
set 'cal $MONTH $YEAR'
shift $(($# - 1))
KEEPDAYS=$1
fi

DATE=$YEAR$MONTH$KEEPDAYS

dir=$PWD
fileExp=$DATE

if [ "X${fileExp}" != "X" ] ; then
for file in `find . -name \*$fileExp\*`
do
echo $file
done
fi


Report Offensive Message For Removal


Response Number 1
Name: LiteBright
Date: December 14, 2006 at 08:48:34 Pacific
Subject: Files Not Being Listed
Reply: (edit)
I've also noticed that if I change the month and year to a leap year, say march 3, 2004. the value in KEEPDAYS comes back with garbage.

Report Offensive Follow Up For Removal

Response Number 2
Name: nails
Date: December 14, 2006 at 10:49:53 Pacific
Subject: Files Not Being Listed
Reply: (edit)
You don't say which Unix and shell you're using - looks like ksh or bash, but your script works fine on my Solaris 9 box using ksh. I suspect your problem is the way you are building the find command. I'd try replacing this:

if [ "X${fileExp}" != "X" ] ; then
for file in `find . -name \*$fileExp\*`
do
echo $file
done
fi

with this:


if [ ! -z ${fileExp} ]
then
find . -name "*${fileExp}*" -print|while read myfile
do
echo "${myfile}"
done
fi
# end stub

Regarding your second question, I don't understand. If you are going to use a date other than the system date, you have to find another method for determining KEEPDAYS other than the date command.



Report Offensive Follow Up For Removal

Response Number 3
Name: LiteBright
Date: December 15, 2006 at 07:17:48 Pacific
Subject: Files Not Being Listed
Reply: (edit)
I'm sorry I just realized I stated my problem wrong. I need to list files that have a date that is older than DATE=$YEAR$MONTH$KEEPDAYS

I am using ksh on Unix.


Report Offensive Follow Up For Removal

Response Number 4
Name: nails
Date: December 15, 2006 at 11:34:02 Pacific
Subject: Files Not Being Listed
Reply: (edit)
Now, I'm confused how KEEPDAYS is determined.

Have you considered using the find command's modification time option:


-mtime n
True if the file's data was modified n days ago.

Also, there's a method for finding files modified within a given date range using find's -newer option. It's discussed here:

http://www.unixreview.com/documents...



Report Offensive Follow Up For Removal

Response Number 5
Name: LiteBright
Date: December 15, 2006 at 12:00:57 Pacific
Subject: Files Not Being Listed
Reply: (edit)
KEEPDAYS is determined by the calender day - 7
typeset -Z2 KEEPDAYS=$((`date +%d` -7))

I then want to be able to list files that are older than the KEEPDAYS number.

Filenames are stored as PDFBOLS20061214165246310048A1DE00002. After the date and time stamp, the rest is randomly generated.
I need to be able to list any file that is older than the date the has been inserted into the filename '20061214'. So I should see '*20061207*' '*20061206*' '*20061205*' etc.


Report Offensive Follow Up For Removal


Response Number 6
Name: LiteBright
Date: December 15, 2006 at 12:06:50 Pacific
Subject: Files Not Being Listed
Reply: (edit)
Using find -mtime would delete other files that should not be deleted. In the script before I could just delete anything just by using the just the year. I now need to keep the selected files if they are 0-7 days old. >7 They need to be listed and removed.

Report Offensive Follow Up For Removal

Response Number 7
Name: nails
Date: December 15, 2006 at 12:26:59 Pacific
Subject: Files Not Being Listed
Reply: (edit)
Why don't you use a combination of file name and modification time? Won't the modification time be clase to the time stamp embedded in the file name?

YEAR=2006
MONTH=12

FileExp=

find . -type f -name "PDFBOLS*${YEAR}${MONTH}*" -mtime ....


Report Offensive Follow Up For Removal

Response Number 8
Name: LiteBright
Date: December 19, 2006 at 09:13:26 Pacific
Subject: Files Not Being Listed
Reply: (edit)
Thanks a lot for the help nails. I ended up using this:
YEAR=`date +%Y`

find $dir -type f -name "PDFBOLS${YEAR}*" ! -mtime -7 -print|sort|while read myfile
do
ls -l $myfile
rm -f $myfile
done

Thanks again.


Report Offensive Follow Up For Removal

Response Number 9
Name: nails
Date: December 19, 2006 at 18:07:20 Pacific
Subject: Files Not Being Listed
Reply: (edit)
you are welcome

Report Offensive Follow Up For Removal



Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Files Not Being Listed

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




My PC has been hijacked!

Lexmark 2600 Printer Issues

btk1w1 infected start here post

Unwanted message remians on screen

Slow boot time


The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC