Checking for proper number of files in dir


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Checking for proper number of files in dir
# 1  
Old 12-07-2008
Checking for proper number of files in dir

Using Solaris 10 and sh.

I have three files.
mydirs.txt
/dir1/dir2/dir3
/dir4/dir5/dir6

mydirshave.txt
1
2

mydirsshouldhave.txt
2
2

For each directory listed in mydirs.txt I should have the number of files equal to mydirshouldhave.txt. But using -ls |wc -l- on the dirs I get what is in mydirshave.txt. So I want to error with dir3 as it is short. All three files will have the same number of lines. I know how to get the three files above. I am trying to find the best method to check for ones that do not have the correct number of files. I am not an expert but I put this together to try and get the point across further:
Code:
dir= `cat mydirs.txt`
shouldhave= `cat mydirsshouldhave.txt`
have= `cat mydirshave.txt`
;do
if test -d $dir
then
$shouldhave=$have GOOD
else
error BAD

I don't have to bring in the mydirshave.txt files if I am doing the ls |wc -l in the script. Thanks in advance!

Last edited by crowman; 12-07-2008 at 05:47 PM..
# 2  
Old 12-11-2008
I notice you posted 4 days ago, any progress or do you still need a hand?
# 3  
Old 12-12-2008
Sorry, I haven't gone through the post completely

Code:
dir= `cat mydirs.txt`

should be as

Code:
dir=`cat mydirs.txt`

( no space between = and ' )
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Assign read write permission to the user for specific dir and it's sub dir and files in AIX

I have searched this quite a long time but couldn't find the right method for me to use. I need to assign read write permission to the user for specific directories and it's sub directories and files. I do not want to use ACL. I do not want to assign user the same group of that directories too.... (0 Replies)
Discussion started by: blinkingdan
0 Replies

2. Shell Programming and Scripting

Checking dir and files!

Hi Guys, I wrote a code which checks for the text and directory. If the path is incorrect than it should echo that particular path not found. I can create a different if statments but I want to do this in just one if statment with the use of "or" (||). I have succssfully executed this code but now... (2 Replies)
Discussion started by: dixits
2 Replies

3. Shell Programming and Scripting

KSH - Find paths of multiple files in CC (dir and sub-dir))

Dear Members, I have a list of xml files like abc.xml.table prq.xml.table ... .. . in a txt file. Now I have to search the file(s) in all directories and sub-directories and print the full path of file in a output txt file. Please help me with the script or command to do so. ... (11 Replies)
Discussion started by: Yoodit
11 Replies

4. Shell Programming and Scripting

Find the number of files older than 1 day from a dir

Hello All, I need to write a script/command which can find out the number of .csv files residing in a directory older than 1 day. The output should come with datewise (means for each date how many files are there). I've this command, but this command gives the total number of files. It's... (10 Replies)
Discussion started by: NARESH1302
10 Replies

5. UNIX for Dummies Questions & Answers

How to list all files in dir and sub-dir's recursively along with file size?

I am very new to unix as well as shell scripting. I have to write a script for the following requirement. In have to list all the files in directory and its sub directories along with file path and size of the file Please help me in this regard and many thanks in advance. (3 Replies)
Discussion started by: nmakkena
3 Replies

6. Shell Programming and Scripting

moving files from a dir in one machine to a dir in another machines

Hi, I am a unix newbie.I need to write a shell script to move my oracle READ WRITE datafiles from one serevr to another. I need to move it from /u01/oradata/W1KK/.. to /u01/oradata/W2KK, /u02/oradata/W1KK/.. to /u02/oradata/W2KK. That is, I actaully am moving my datafiles from one database to... (2 Replies)
Discussion started by: mathews
2 Replies

7. Shell Programming and Scripting

A script to find dir, delete files in, and then del dir?

Hello!! I have directories from 2008, with files in them. I want to create a script that will find the directoried from 2008 (example directory: drwxr-xr-x 2 isplan users 1024 Nov 21 2008 FILES_112108), delete the files within those directories and then delete the directories... (3 Replies)
Discussion started by: bigben1220
3 Replies

8. Shell Programming and Scripting

home dir checking

Hi, I want suggestion about user home directories, checking. how i could calculate this. I have 200 Users. if home-dir-of-user1 > 250 MB -> print "OK" fi if home-dir-of-user1 > 500 MB > Print "Warning" fi if home-dir-of-user1 > 1000 MB > Print "Critical" fi Thanks, Bash (4 Replies)
Discussion started by: learnbash
4 Replies

9. Shell Programming and Scripting

Checking the directory and concatenate the data of all the log files in that dir

Hi Gurus, I am new to unix and need your help to make a shell script. I have a requirement, would appreciate if you could please help me on it: Requirement: ------------- I will pass 2 parameters in shell script 1). Directory name say errors 2). file extension say .log First of all this... (4 Replies)
Discussion started by: anshulinpc
4 Replies

10. UNIX for Advanced & Expert Users

Number of open files (Dir's) how to close?

I am having a client/server application which will download files from server. If server has directories, it will create directories/sub directories and then download files. In this process, I observed that number of open files are more than 400 (which is approxmately same as number of dir/subdir... (1 Reply)
Discussion started by: satyam90
1 Replies
Login or Register to Ask a Question