Sponsored Content
Top Forums Shell Programming and Scripting Help needed to print the not updated files in the Directory Post 302732591 by bbc17484 on Sunday 18th of November 2012 03:00:04 PM
Old 11-18-2012
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.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

print all files of a directory

At the moment I do not know anything UNIX script :rolleyes: but i need to make script that prints the content of the archives (of text) that are deposited in a directory and Later erases these archives, leaving the directory emptiness It would be like repository for print please... (9 Replies)
Discussion started by: monica
9 Replies

2. Shell Programming and Scripting

Find recently updated files in home directory

Is there a shell command that will allow me to list index files in the /home directory for all users on a server that have been updated within the past 24 hours? (e.g. index.htm .html .php in/home/user1/public_html /home/user2/public_html /home/user3/public_html etc ) (2 Replies)
Discussion started by: Kain
2 Replies

3. Shell Programming and Scripting

Help needed with searching files and moving them to a different directory

I am new to shell scripting. Can someone help me out with this one please? I need to write a script fot the following scenario: I am currently in /parent directory. I have a set of files in /parent/error_files directory My script has to search for a file in /parent/erratic_files... (1 Reply)
Discussion started by: ss3944
1 Replies

4. Shell Programming and Scripting

Print the name of files in the directory using Perl

Hi All, I am stuck with a problem and i want your help, what i want to do is I have a directory name dircome and there are 6 files present in this directory, the name of the files are d1,d2,d3,d4,d5,d6. The Perl script print the files name, means the output should be d1 d2 d3 d4 d5 d6 (9 Replies)
Discussion started by: parthmittal2007
9 Replies

5. Shell Programming and Scripting

Find out whether directory has been updated with files in the last 5 minutes or not

Hi, I am trying to work on this script that needs to monitor a Directory. In case there are no files received in that Directory for the last 5 minutes, it has to send out an alert. Could someone please suggest any approach for the same. Note: I did check out various previous psts -... (8 Replies)
Discussion started by: rituparna_gupta
8 Replies

6. UNIX for Advanced & Expert Users

AIX idea needed to check the logs updated date and time

Hi with the help of Gabriel canepa, i have just edited filename only in his code. The help which i got and he helped is 1) I have around 22 logs and each log should be updated in the last 24 hours from the current timestamp. 2) It should check for ERROR message (not error,Error) in the log and... (2 Replies)
Discussion started by: Kalaihari
2 Replies

7. Shell Programming and Scripting

Script needed to delete to the list of files in a directory based on last created & delete them

Hi My directory structure is as below. dir1, dir2, dir3 I have the list of files to be deleted in the below path as below. /staging/retain_for_2years/Cleanup/log $ ls -lrt total 0 drwxr-xr-x 2 nobody nobody 256 Mar 01 16:15 01-MAR-2015_SPDBS2 drwxr-xr-x 2 root ... (2 Replies)
Discussion started by: prasadn
2 Replies

8. Shell Programming and Scripting

Directory containing files,Print names of the files in the directory that are exactly same content.

Given a directory containing say a few thousand files, please output a list of all the names of the files in the directory that are exactly the same, i.e. have the same contents. func(a_directory_name) output -> {“matches”: , ... ]} e.g. func(“/home/my/files”) where the directory... (7 Replies)
Discussion started by: anuragpgtgerman
7 Replies

9. UNIX for Beginners Questions & Answers

Search strings from a file in files in a directory recursively; then print the string with a status

Hi All, I hope somebody would be able to help me. I would need to search a string coming from a file, example file.txt: dog cat goat horse fish For every string, I would need to know if there are any files inside a directory(recursively) that contains the string regardless of case.... (9 Replies)
Discussion started by: kokoro
9 Replies

10. UNIX for Beginners Questions & Answers

Print number of lines for files in directory, also print number of unique lines

I have a directory of files, I can show the number of lines in each file and order them from lowest to highest with: wc -l *|sort 15263 Image.txt 16401 reference.txt 40459 richtexteditor.txt How can I also print the number of unique lines in each file? 15263 1401 Image.txt 16401... (15 Replies)
Discussion started by: spacegoose
15 Replies
FLOCK(1)						    BSD General Commands Manual 						  FLOCK(1)

NAME
flock -- Provide locking API for shell scripts SYNOPSIS
flock [-dnosvx] [-w timeout] lockfile|lockdir [-c command] | [command ...] flock [-dnsuvx] [-w timeout] lockfd DESCRIPTION
The flock utility provides flock(2) access to the command line or scripts. The first form locks a file or directory while the command pro- vided is executed. If the file or directory does not exist, then a file is created. The second form can use an arbitrary file descriptor that is provided from a shell script for example: ( flock -s 100 # commands to be executed under the lock ) 100> /path/to/lockfile The following options are available: -c command Pass a command to a the shell. -d, --debug Provide debugging output. -n, --nb, --nonblock Don't block and fail immediately if the lock could not be obtained. -o, --close Close the file before executing the command. This is useful if the child forks and should not be holding the lock. -s, --shared Obtain a shared lock. -u, --unlock Unlock an existing lock. This is available only for a file descriptor. -v, --verbose On error print an explanation of the failure. -w, --wait, --timeout seconds Fail if the lock could not be obtained after seconds. -x, --exclusive Obtain an exclusive lock. EXIT STATUS
The flock utility exits 0 on success, and >0 if an error occurs. SEE ALSO
shlock(1), flock(2) HISTORY
An flock utility appeared in NetBSD 6.1. BSD
November 2, 2012 BSD
All times are GMT -4. The time now is 09:59 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy