Script to send email if count is >1


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to send email if count is >1
# 1  
Old 04-01-2014
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, couldn't figure out the issue, is the approach correct or is there a better way for this approach




Code:
#! /usr/bin/kshAttachment = file1.txtNumber_of_lines = wc -l < file1.txtEmail_Id=abc@email.comif [ $Number_of_lines > 1 ] then (echo "Find Attached the Error File which list the Error Rows from Invalid Procedure codes";uuencode $Attachment Invalid_Procedure_Codes.txt) | mail -s "[ERROR] : Invalid Procedure codes " $Email_Idfi


Last edited by srini_106; 04-02-2014 at 01:08 PM..
# 2  
Old 04-01-2014
Moderator's Comments:
Mod Comment Posting "Does not work" without explanation does not help you or anyone. If a command does not work for you, please show the exact circumstances you used it, and the exact error or malfunction you received. Do not paraphrase errors, or post the text as links, images, or attachments if you can avoid it: Paste the exact message, in code tags, like [code] text [/code] or by selecting the text and using the Image button.

Thank you.

The UNIX and Linux Forums
# 3  
Old 04-02-2014
This works...
Code:
#! /usr/bin/ksh
Attachment=file1.txt
Number_of_lines=$(wc -l file1.txt | awk '{print $1}')
echo ${Number_of_lines}
Email_Id="user@somehost.com"

if (( ${Number_of_lines} > 1 ))
then
 (echo "Find Attached the Error File which list the Error Rows from Invalid Procedure codes";uuencode  ${Attachment} ${Attachment}) | mailx -s "[ERROR] : Invalid Procedure codes " ${Email_Id}
fi

# 4  
Old 04-02-2014
If you're doing command | command | awk, you might as well throw out all the stuff before it and just use awk.

Code:
LINES=$(awk 'END { print NR }' file1.txt)

# 5  
Old 04-02-2014
Or this
Code:
#!/bin/sh
Attachment=file1.txt
Number_of_lines=`wc -l < $Attachment` 
Email_Id=abc@email.com
if [ $Number_of_lines -gt 1 ]
then
(
echo "Find Attached the Error File which lists the Error Rows from Invalid Procedure codes"
uuencode $Attachment Invalid_Procedure_Codes.txt
) |
mail -s "[ERROR] : Invalid Procedure codes" $Email_Id
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need little script to send out email

Hi Scripters, good day. bash-4.2# df -g /apps/prd Filesystem GB blocks Free %Used Iused %Iused Mounted on /dev/xxx 64.00 4.35 94% 1269284 8% /xxx bash-4.2# I was wondering if there is a script when the usage of the mountpoint above hit 98%, email would be... (3 Replies)
Discussion started by: jaapar
3 Replies

2. Shell Programming and Scripting

Send email based on row count

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,... (1 Reply)
Discussion started by: srini_106
1 Replies

3. Shell Programming and Scripting

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... (2 Replies)
Discussion started by: atrailm
2 Replies

4. Shell Programming and Scripting

Help with shell script to send email once

Hi Guys, I have this script which will monitor oracle db process if up or down.And I want it to send email if it's down and the time it's back to online. However my script just keep on sending "Email Up" if the db is up or "Email Down" if the db is down.Is there any way to trap it so that it... (5 Replies)
Discussion started by: d3xt3r
5 Replies

5. Shell Programming and Scripting

Script to send email after comparing the folder permissions to a certain permission & send email

Hello , I am trying to write a unix shell script to compare folder permission to say drwxr-x-wx and then send an email to my id in case the folders don't have the drwxr-x-wx permissions set for them . I have been trying to come up with a script for few days now , pls help me:( (2 Replies)
Discussion started by: nairshar
2 Replies

6. Shell Programming and Scripting

How to send email through shell script

Hi All, I am new to the unix , i have to deliver one script very urgently I have to write a shell script where i have i want to send email to specific email id in this script i want FROM to be parameterized and stored in a variable TO to be parameterized and stored in a variable... (3 Replies)
Discussion started by: nileshbhawsar
3 Replies

7. Shell Programming and Scripting

Send email on script error

I need to start off by saying that I am not much of a programmer and know enough to cause lots of trouble. I've been writing this script to decrypt an XML feed, then parse the feed into a database. The script is executed from cron. #!/bin/sh PGPPATH=/path/to/directory echo "pgp... (6 Replies)
Discussion started by: Aslan_Eident
6 Replies

8. Shell Programming and Scripting

script to send a file in email

a file is created on a daily basis in the name xyz_pqr_20071207.dat.i want to send the file as an attachment if the file contains more than 50 records.how can i write a script such that it will transmit the file after the file is created.i want to sed the file to say asdf@xyz.com. please help me... (2 Replies)
Discussion started by: dr46014
2 Replies

9. Shell Programming and Scripting

script that will send and email attachment

I'm looking for a sample of some code that will take the output from a file and generate an email that will include that text as an attachment. the script is in the borne shell. any help? (2 Replies)
Discussion started by: davels
2 Replies
Login or Register to Ask a Question