Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-05-2013
Registered User
 
Join Date: Jun 2012
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Email Command Error

Hi ,

i am very new unix i need a script which should check for the size of the file and if it is greater than zero ,than i have copy the contain of the file (the file we have checked the size) as body .


Thanks
Anuddep
Sponsored Links
    #2  
Old 01-05-2013
kshji's Avatar
Registered User
 
Join Date: Jun 2009
Location: Finland
Posts: 575
Thanks: 0
Thanked 46 Times in 45 Posts

Code:
#!/bin/somesh
# arg 1 is the filename
SM="/usr/lib/sendmail -t -i "
fname="$1"
[ "$fname" = "" ] && echo "usage:$0 file" >&2 && exit 2

# test size of file using -s = size > 0
# -f test only file, size 0 is also true
[ ! -s "$fname" ] && exit 1

$SM <<EOF
From: myemail@mydomain
To: someemail@somedomain
Subject: File $fname include something

$(<$fname)


-myname-


EOF

Sponsored Links
    #3  
Old 01-05-2013
Registered User
 
Join Date: Jun 2012
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Email Command Error

@kshji ,


kindly can you please explain the script
    #4  
Old 01-05-2013
Yoda's Avatar
Jedi Master
 
Join Date: Jan 2012
Location: Galactic Empire
Posts: 2,514
Thanks: 167
Thanked 817 Times in 786 Posts
Using mailx


Code:
FILE=$1                                                         # Accept file name as argument.

[[ -s "$FILE" ]] && mailx -s "Subject" user@host.com < $FILE    # Check file size if > 0, then send mail

Sponsored Links
    #5  
Old 01-05-2013
Registered User
 
Join Date: Nov 2012
Posts: 33
Thanks: 3
Thanked 1 Time in 1 Post
I prefer and recommend mailx. I hope you don't need further explanation of bipinajith's script.
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Using top command to email if process is exceeding 25% and sending an email alert if so jay02 Shell Programming and Scripting 8 03-02-2012 11:36 AM
How to create a script that will email once there is an error? rymnd_12345 UNIX for Dummies Questions & Answers 2 12-26-2011 11:48 PM
Error while sending email from solaris Danish Shakil Shell Programming and Scripting 0 03-05-2009 08:39 AM
VIP membership email error DeepakS Post Here to Contact Site Administrators and Moderators 1 12-16-2008 02:54 PM
Text File error in email mgirinath Shell Programming and Scripting 3 07-12-2006 06:10 AM



All times are GMT -4. The time now is 01:10 AM.