Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

find matched files

Posted on 2011-03-21
4
Medium Priority
?
312 Views
Last Modified: 2012-05-11
Hi, suppose my current path is /scratch/zh/imp/out. There are 22 sub-directories called "1","2",..."22".
In each sub-folder, there are many .gz files and .summary files. In the normal situation, there is a corresponding .gz file for each .summary file.
But sometimes it is not correct due to lacking of enough cpu time to cause jobs failure.

I want a shell scipt to check the case. If the situation happened, find which folder failed.

Thanks for help.
0
Comment
Question by:zhshqzyc
  • 2
4 Comments
 
LVL 23

Expert Comment

by:Kamaraj Subramanian
ID: 35181475

for i in `find . -type d`
do
	ls -l $i | grep ".gz$" > /dev/null
	[ "$?" eq "0" ] && echo "$i has .gz file" || echo "$i does not have .gz file"
	ls -l $i | grep ".summary$" > /dev/null
	[ "$?" eq "0" ] && echo "$i has .summary file" || echo "$i does not have .summary file"
done

Open in new window

0
 
LVL 23

Assisted Solution

by:Kamaraj Subramanian
Kamaraj Subramanian earned 280 total points
ID: 35181519
you can use `find . -maxdepth 1 -type d` for only for one level
0
 
LVL 8

Assisted Solution

by:pilson66
pilson66 earned 240 total points
ID: 35181651
script:
 
#!/bin/bash

firstdir="/path/to/dirs"

for t in $(seq 1 22); do
    cd ${firstdir}/${t}
        for w in $(ls *.summary | sed 's/\.summary//g'); do
            if [ ! -f ${w}.gz ]; then
                echo "Error: ${t}: ${w}.gz is absent."
            fi
        done
done

Open in new window


result:
 
./1.sh 
Error: 2: qwe.gz is absent.

Open in new window

0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 480 total points
ID: 35181821
find /scratch/zh/imp/out -name "*gz" -o -name "*.summary" |sort | sed  s'/\.summary$//;s/\.gz$//' | uniq -u
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
I have written articles previously comparing SARDU and YUMI.  I also included a couple of lines about Easy2boot (easy2boot.com).  I have now been using, and enjoying easy2boot as my sole multiboot utility for some years and realize that it deserves …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month11 days, 5 hours left to enroll

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question