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.
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
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.
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.
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.
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