Objective: find in a path directories that are named Logs. In each found Logs dir search for files with .log extension and remove -atime +6. (Note for test/example, rm and -atime is not used).
Issue: If I execute the script without redirecting output to a file, on stdout gives me what I expect to see. Redirecting it to an out put file results in output file having result of last iteration as well as ls -l of the directory where this script resides.
Disclaimer: I know that I am doing something silly here but cannot pin point.
Thank you in advance. I know that I need to do the search and sub searc on iteration basis, have been searching threads here and even used some suggestion but I am failing to correctly construct a do routine.
Well, no space after #!, you truncate the output for every DIR, xargs will fire for 0 found, so try -n999, and while read DIR' would be lower latency:
find -atime seems a flaky condition; usually people go by -mtime, or simpler yet, robust, testable and accurate: "-newer $marker_file" like this:
Hi there and thank you Corona688 and DGPicket for your time and advice.
I tried both suggestions. There are two things occurring:
1. stdout does show per dir listing of .log files, however, the last two in iteration also show a ls -l of the directory where this script is saved. Very odd.
OS is Linux.
Noted your advice Corona. Also, will change the -atime. DG, your newer file example went way over my head
1. stdout does show per dir listing of .log files, however, the last two in iteration also show a ls -l of the directory where this script is saved. Very odd.
I think that means xargs didn't find any arguments and just ran ls -l by itself. -n999 doesn't actually stop this from happening, it only sets a maximum number of args, so seems a bit pointless.
xargs can also react badly to spaces in filenames since it takes any whitespace as the separator. You can force it to use newlines only with -d '\n' but the preferred solution, in Linux, would be to use find -print0 and xargs --null. like find "$DIR" -type f -name "*.log" |xargs ls -l Also note the extra quotes around $DIR. If there were any spaces in it, the quotes would stop it from splitting into two or more arguments.
Last edited by Corona688; 03-17-2011 at 05:10 PM..
Hi all and thank you for your valuable suggestions. I learned quite a bit.
I played around and made some changes in the search routine to check if dir is empty or not and used the following in my code and it is working as I liked:
Once I am done testing I will add the -mtime option in my search feature as suggested.
Hi. Can somebody tell me if there's a way of creating a symbolic link from a directory on one filesystem to that on another that will allow a find command that doesn't use the -L param to locate a particular file under that new 'linked' dir. With a normal sym link the find command on that... (6 Replies)
Hello,
I'm having a trouble with the find cmd.
I would like to find all the java versions on my systems.
I have solaris 9 & 10 RHEL and SUSIE.
java -version
doesn't give all the versions on the server.
So I am trying to use the find command to find them all
find / -name java
I would... (7 Replies)
/usr/bin/find $SEARCH_DIR -daystart \( \( -name 'KI*' -a -name '*.csv' \) -o -name '*_xyz_*' \) -mtime $DAYS_AGO -printf %f -printf "\n" | sort -r > $FILES
The above command gives different results when run on a cron job. When run manually the result is accurate. (2 Replies)
Hi All,
My target is to find the biggest files opened by any process and from that i have to find process id and the corresponding file also to avoid file system being hung-up.
Finding the process id: is to kill the process
Finding the biggest file: is to remove the file
To get the process... (0 Replies)
I am trying to copy 2 types of files so I can archive them. I tested with a set of commands:
touch -t $(date -d "-60 day" +%Y%m%d) WORKDIR/REF
find TARGETDIR/ -type f -maxdepth 1 -iname \*.out\* -or -iname \*.log\* ! -newer WORKDIR/REF -exec ls -l {} \;
This correctly lists any files in the... (2 Replies)
In shell we can find the status of last executed command by $?
In perl what is the command to find the status of last executed command...
Can any one please say???????????????
Thanks,
Prabhu (1 Reply)
i have a list of files below:
rwxrwxrwx 1 pipe pipe 180 Mar 4 22:47 del_0n_Date
-rwxrwxrwx 1 pipe pipe 472 Mar 4 22:58 mail_Check
-rw-r--r-- 1 pipe pipe 92 Mar 4 22:58 minfo.txt
-rwxrwxrwx 1 pipe pipe 609 Mar 5 05:12... (6 Replies)
Hi,
i wan to search the file starting with Admin into the directory Output. I am running below command:
find /appl/Output -name "Admin*" -prune
but this command is going into the sub directories present under output. I do not want to search under sub directories. Any help will be highly... (6 Replies)