Email Command Error | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

Email Command Error

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-05-2013
kkabc789 kkabc789 is offline
Registered User
 
Join Date: Jun 2012
Last Activity: 7 January 2013, 10:46 PM EST
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
kshji kshji is offline
Registered User
 
Join Date: Jun 2009
Last Activity: 26 February 2014, 5:44 AM EST
Location: Finland
Posts: 602
Thanks: 0
Thanked 50 Times in 49 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
kkabc789 kkabc789 is offline
Registered User
 
Join Date: Jun 2012
Last Activity: 7 January 2013, 10:46 PM EST
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
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 25 July 2014, 1:29 AM EDT
Location: Galactic Empire
Posts: 3,355
Thanks: 230
Thanked 1,190 Times in 1,123 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
phunk phunk is offline
Registered User
 
Join Date: Nov 2012
Last Activity: 28 February 2014, 3:57 PM EST
Posts: 35
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
Closed Thread

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 07:17 AM.