Solved

find matched files

Posted on 2011-03-21
4
301 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 70 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 60 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 120 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.

785 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