Help needed to print the not updated files in the Directory

Hi All,

I have written one program to print the files which are not updated in the specified directory in .Dat file. If I am executing the same command in the command prompt its working fine but if I am executing in shell script it's not working fine. Please correct if any thing wrong in the below script

My requirement is, I want the files which are not updated in last 7 days

#set -vx
#!/bin/ksh

day_chk=`expr $(nzsql -host ${NZ_HOST} -db ${NZ_DATABASE_LOG}  -A -t -c "SELECT TO_CHAR(CURRENT_DATE,'DD')") - 7`
mon_chk=`expr $(nzsql -host ${NZ_HOST} -db ${NZ_DATABASE_LOG}  -A -t -c "SELECT TO_CHAR(CURRENT_DATE,'Mon')")`

echo "day_chk " $day_chk
echo "mon_chk " $mon_chk
echo $DIR_DATATGT_BPS


ls -ltr ${DIR_DATATGT_BPS}/*.lst | awk '$7 < $day_chk && $6 == "$mon_chk" { print $9 }' > ${DIR_TEMP}/Non_Updated_Files.dat

file_count=`cat ${DIR_TEMP}/Non_Updated_Files.dat | wc -l`
echo "File Count :"$file_count

Please let me know what is the issue in that code.

example

-rwxr-xr-x  1 chandu cvcinfm   5956 Nov 2 03:40 file1.ksh
-rwxrwxrwx  1 chandu cvcinfm   5432 Nov 2 03:52 file2.ksh
-rwxr-xr-x  1 chandu cvcinfm   3147 Nov 16 16:58 file3.ksh

i want to print

file1.ksh
file2.ksh in my output file

Thanks,
Chandu.

The find command should get this info for you:

find "$DIR_DATATGT_BPS" -name '*.lst' -mtime +7 -print > $DIR_TMP/Non_Updated_Files.dat
1 Like

I have adjusted the quotes in my code, that is also working.

awk '$7 < '$day_chk' && $6 =="'$mon_chk'" { print $9 }' > temp.dat

Be wary of your solution in the first week of a month/year