Help needed to print the not updated files in the Directory | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Help needed to print the not updated files in the Directory

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 11-18-2012
bbc17484 bbc17484 is offline
Registered User
 
Join Date: Feb 2008
Last Activity: 17 February 2014, 2:17 PM EST
Location: Charlotte, NC
Posts: 30
Thanks: 16
Thanked 0 Times in 0 Posts
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


Code:
#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


Code:
-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.
Sponsored Links
    #2  
Old 11-18-2012
Chubler_XL's Avatar
Chubler_XL Chubler_XL is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 23 July 2014, 12:31 AM EDT
Posts: 2,728
Thanks: 101
Thanked 844 Times in 795 Posts
The find command should get this info for you:


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

The Following User Says Thank You to Chubler_XL For This Useful Post:
bbc17484 (11-18-2012)
Sponsored Links
    #3  
Old 11-18-2012
bbc17484 bbc17484 is offline
Registered User
 
Join Date: Feb 2008
Last Activity: 17 February 2014, 2:17 PM EST
Location: Charlotte, NC
Posts: 30
Thanks: 16
Thanked 0 Times in 0 Posts
I have adjusted the quotes in my code, that is also working.


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

    #4  
Old 11-18-2012
Chubler_XL's Avatar
Chubler_XL Chubler_XL is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 23 July 2014, 12:31 AM EDT
Posts: 2,728
Thanks: 101
Thanked 844 Times in 795 Posts
Be wary of your solution in the first week of a month/year
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Find out whether directory has been updated with files in the last 5 minutes or not rituparna_gupta Shell Programming and Scripting 8 06-22-2012 11:27 AM
Print the name of files in the directory using Perl parthmittal2007 Shell Programming and Scripting 9 03-14-2012 03:28 AM
Help needed with searching files and moving them to a different directory ss3944 Shell Programming and Scripting 1 12-23-2009 12:35 PM
Find recently updated files in home directory Kain Shell Programming and Scripting 2 10-31-2008 08:20 PM
print all files of a directory monica Shell Programming and Scripting 9 11-04-2006 09:02 AM



All times are GMT -4. The time now is 01:46 AM.