Simple script to count files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Simple script to count files
# 1  
Old 09-17-2010
Simple script to count files

Hello,
I am new to shell scripting and I need your help.
I have found similar scripts in the forum but I need further assistance.

I am building a script to use hourly in cron to mailx me if the number of files in a path is less than e.g 100

I have started with the following:

Code:
#!/bin/sh
ymdh=`${LIB}/YYYYMMDDHH24-2`    <-GATHERED FROM ORACLE SCRIPT
while true ; do
cd /Data/ftpdir
files_count =`$ll *${ymdh}* |wc -l`
if [ ${files_count} < 100 ]
then

      mailx "No_of_files_2 _hrs_before" ............................
fi
done


Any help will be much appreciated.

Last edited by Scott; 09-17-2010 at 08:09 AM.. Reason: Please use code tags
# 2  
Old 09-17-2010
Hi, as you will have a cron job that will run hourly, you don't really need the "while true" part.

The script is:
Code:
#!/bin/sh
checkPath="<PathToCheck>"
minNumberOfFiles=100
numOfFiles=`ls -l "${checkPath}" | egrep '^-r' | wc -l`

if [ ${numOfFiles} -lt ${minNumberOfFiles} ]
then
echo "Number Of Files In: [${checkPath}] Less Than ${minNumberOfFiles}: [${numOfFiles}]" | mailx -s "Num Of Files" you@example.com
fi

Of course, there are other ways to do it! You can change numOfFiles to:
Code:
numOfFiles=`find ${checkPath} -type f -maxdepth 1 | wc -l`

This User Gave Thanks to felipe.vinturin For This Post:
# 3  
Old 09-17-2010
Thank you !
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Script /commands to get all the files count

Hello All, I would need to write a shell script to find the files generation count for the given day and the folder.Presently I am using (ls -ltr *filename* | grep "Feb 19" | wc -l ) from each folder and getting the counts.I would like to create a script which will get the counts under the... (3 Replies)
Discussion started by: ravish383
3 Replies

2. Shell Programming and Scripting

Shell script for field wise record count for different Files .csv files

Hi, Very good wishes to all! Please help to provide the shell script for generating the record counts in filed wise from the .csv file My question: Source file: Field1 Field2 Field3 abc 12f sLm 1234 hjd 12d Hyd 34 Chn My target file should generate the .csv file with the... (14 Replies)
Discussion started by: Kirands
14 Replies

3. Shell Programming and Scripting

Error files count while coping files from source to destination locaton as well count success full

hi All, Any one answer my requirement. I have source location src_dir="/home/oracle/arun/IRMS-CM" My Target location dest_dir="/home/oracle/arun/LiveLink/IRMS-CM/$dc/$pc/$ct" my source text files check with below example.text file content $fn "\t" $dc "\t" $pc "\t" ... (3 Replies)
Discussion started by: sravanreddy
3 Replies

4. Shell Programming and Scripting

Script to compare count of two csv files

Hi Guys, I need to write a script to compare the count of two csv files each having 5 columns. Everyday a csv file is recived. Now we need to compare the count of todays csv file with yesterday's csv file and if the total count of records is same in todays csv file and yesterday csv file out... (3 Replies)
Discussion started by: Vivekit82
3 Replies

5. Shell Programming and Scripting

Script to count number of files in directories

Hi All! I would like to have a script that will count the number of files at the top of the hour of soome directories and mail the results to me. I was thinking on : a=`/directory/subdirectory/ | wc -l` echo "/directory/subdirectory :$a" b=`/another_dir/subdir/ | wc -l` echo... (12 Replies)
Discussion started by: fretagi
12 Replies

6. UNIX for Dummies Questions & Answers

Script to get Row Count of ZIP Files

Hi, I have some data files in a zipped format.(eg: aa.gz).I would like to know the number or rows in each zip file(May be populate the file name and line numbers into a text file).I know the commands wc -l and gunzip,.But how I will create a shell script for this to extract each files and get... (5 Replies)
Discussion started by: abhilash_menon
5 Replies

7. Shell Programming and Scripting

AWK Script - Count Files In Directories

Hey, I'm very new to AWK and am trying to write a script that counts the number of files in all subdirectories. So, basically, my root has many subdirectories, and each subdirectory has many files. How can I get the total count? I haven't been able to figure out how to loop through the... (1 Reply)
Discussion started by: beefeater267
1 Replies

8. Shell Programming and Scripting

script to count files in a directory

Hello, I was wondering if anyone had an answer for this? thanks, KW (3 Replies)
Discussion started by: kwa71
3 Replies

9. UNIX for Dummies Questions & Answers

Simple script for separating files

Hi all, I was wondering if someone could help me writing a simple script on separating files into separate folders. I have 92 files called various things and I want to separate these folders like so: Create a folder called "1" and put files 1-23 in it Create a folder called "2" and put... (5 Replies)
Discussion started by: hertingm
5 Replies

10. Shell Programming and Scripting

simple count script outputting mass errors

script outputting cant find anything wrong with the script either... : #!/bin/sh #count execution script time=0 while do if then time=`expr $time + 1` if then echo "The current tick is 100" fi fi (2 Replies)
Discussion started by: aspect_p
2 Replies
Login or Register to Ask a Question