Script for count files and send mails


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script for count files and send mails
# 1  
Old 12-11-2012
Code Script for count files and send mails

Hi.

I'm new on this forum and I need if possible someone to help me with one script.

The script should act like this:
- should be run by crontab and have next parameters:
script_name $par1 $par2 $par3 $par4

where script will search in dir $par1 for files with mask $par2 and if number of this files is greater than $par3 will send email to $par4.

Till now I manage to get the file number with this command:
Code:
ls -l *sorts 2>/dev/null | awk '/^-/{c++}END{ print c }'

but this will just display the number and don;t help me

May someone help me with this?
Thank you in advance!!!

Moderator's Comments:
Mod Comment Please use code tags next time for your code and data.

Last edited by vbe; 12-11-2012 at 11:29 AM..
# 2  
Old 12-11-2012
How about?
Code:
if [ $( ls -l *sorts 2>/dev/null | awk '/^-/{c++}END{ print c }' ) -gt $par3 ]
then
      echo "Number of files is greater than $par3" | mailx -s "Subject" $par4
fi

# 3  
Old 12-12-2012
Thank you very much. With some little adjustments was working perfect!
Thank you again & have a nice day! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to send email if count is >1

i have below code to count number of rows in file1.txt, if the row count is more than one then i have sending an email along with file1.txt attached and fail the process(do nothing if count is <=1), if I test individually count part works good but when i include the email part its not working,... (4 Replies)
Discussion started by: srini_106
4 Replies

2. UNIX for Advanced & Expert Users

Zip the files if count is more than 0 and send a mail

All, I am new to shell scripting and trying to get the count of files that starts with error and with extension .out, if the count is greater than 0 and zip the file and send an email with the content of error.out file, here is my script cd /temp testcount =$('find . -name '*.out' -print |... (4 Replies)
Discussion started by: luckydoll
4 Replies

3. Shell Programming and Scripting

Send Receive Mails

Hi All, I am writing one script to automate one long process. In this process we need to upload some input files and download some output files. So , I want to automate this upload and download by using mail functionality. I want to trigger this script when I am sending mail to server. I know... (0 Replies)
Discussion started by: NirajThakar
0 Replies

4. UNIX for Advanced & Expert Users

shell script to send separate mails to different users from a text file

Hi Friends, Could you guys help me out of this problem... I need to send an email to all the users and the email has to be picked from the text file. text file contains the no. of records like: Code: giridhar 224285 847333 giridhar276@gmail.com ramana 84849 33884... (0 Replies)
Discussion started by: giridhar276
0 Replies

5. Shell Programming and Scripting

Script to consolidate files as mails,groupid

Hi, I'm newbie in Bash scripting. Here is scenario I've a file which containslist of 100 mailgroup and in a directory i have 100 files with each group's respective mail addresses. I'd like to make one CSV file with this information as follows. consolidated files with mailid,groupname. ... (7 Replies)
Discussion started by: manish123456
7 Replies

6. Red Hat

not able to send mails from linux

I am using centOS 5.3 as server, and i hav installed sendmail-8.13.8-2.el5.i386. But still, m not able to send mails to outer domain. Do i need to configure DNS for this? PLease suggest a step by step guide, if u hav, for the concern, as i m new to linux and sendmail as well.. thanks (1 Reply)
Discussion started by: oracle.test2
1 Replies

7. UNIX for Dummies Questions & Answers

cant send mails with mpack/uuencode AIX 5.3

Hi all, I was using mpack for sending mails with pdf as attachment. It was working well. but some days back my server was shut down forcefully due to power failure and I found now the mails are moving to the queue always. I checked in /var/spool/mail/mqueue. Is the forece shutdown has to do... (0 Replies)
Discussion started by: itesh.dash
0 Replies

8. AIX

Not able to send mails

Hi, I am not able to send mails to the recipents. I am using AIX 5.3 Version and using the below command. cat test.log|mail -s "TestMail" user1@mail.com Can you please tell me is there any configurations to be done or is the above command wrong? Thanks & Regards Sheshadri (3 Replies)
Discussion started by: arsheshadri
3 Replies

9. Shell Programming and Scripting

find files older than 30mins,count and send mail

Hi all, I wrote this script to find files older than time parameter, count the number of files, and send an email to me that some files are in a particular folder. For the particular path, the script should wait delay parameter before running again. For example, assuming the input file looks... (4 Replies)
Discussion started by: kayarsenal
4 Replies

10. Debian

cannot send any mails using mailx

hi howto configure mailx ? kind regards ccc (11 Replies)
Discussion started by: ccc
11 Replies
Login or Register to Ask a Question