Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Email Command Error

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 Unix and Linux 01-05-2013
kshji's Unix or Linux Image
kshji kshji is offline
Registered User
 
Join Date: Jun 2009
Last Activity: 9 April 2015, 2:10 AM EDT
Location: Finland
Posts: 616
Thanks: 0
Thanked 54 Times in 53 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 Unix and Linux 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 Unix and Linux 01-05-2013
Yoda's Unix or Linux Image
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 4 July 2015, 1:12 AM EDT
Location: Galactic Empire
Posts: 3,409
Thanks: 240
Thanked 1,217 Times in 1,143 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 Unix and Linux 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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 02:03 AM.