script to send mail from unix?? | 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.

script to send mail from unix??

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-12-2007
deepaknbk deepaknbk is offline
Registered User
 
Join Date: Jul 2007
Last Activity: 8 August 2011, 7:29 AM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Data script to send mail from unix??

Hi all,

I wrote a shell script to send a mail, it is not showing any errors but i didn't receive any mail

#!/bin/ksh

. ./set_mail_details.ksh

echo 'In script'
subject=$1
echo '\nsubject'
echo $1
echo "$subject" | sed 's/~/ /g' | read sub
body_of_email=$2
echo '\nBody'
echo $2
echo '\nMail List'
to_list=$3
echo $3
echo "$body_of_email" | sed 's/~/ /g' | read body
(echo "$body";echo '\n';cat U.CUE_CPM )| mailx -s "$sub" -r some_address@some_mail.com "$to_list"
if [ $? -eq 0 ]
then
echo "Mail is Sent"
else
echo "Mail is not sent(In script)"
fi

output:
$ send_mail.ksh hi test some_address@some_mail.com
In script
subject
hi
Body
test
Mail List
some_address@some_mail.com
Mail is Sent

can any one please help me what is wrong in my script.

Last edited by blowtorch; 07-12-2007 at 06:39 AM.. Reason: remove email address
Sponsored Links
    #2  
Old 07-12-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
 
Join Date: Mar 2007
Last Activity: 21 June 2012, 3:19 PM EDT
Location: Bahia, Brazil
Posts: 1,203
Thanks: 1
Thanked 103 Times in 100 Posts
Deepaknbk,
I tested your script several times and it worked every time,
except when I placed the wrong e-mail address either in the
receiver or with the '-r' option.

Make sure your e-mail addresses are correct.

Good luck!
Sponsored Links
    #3  
Old 08-21-2008
tahseen tahseen is offline
Registered User
 
Join Date: Aug 2008
Last Activity: 21 August 2008, 6:03 AM EDT
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
shell script

can anybody pls help me in writing a shell script to send a automatic email to a team if the mount point size increases to 70mb. for example consider /u01 mount point in a linux platform using bash shell. pls do help.

thanks
tahseen
    #4  
Old 08-21-2008
sakthifire sakthifire is offline
Registered User
 
Join Date: Apr 2008
Last Activity: 16 May 2011, 12:10 AM EDT
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Hi deepa
If you need other way to coding in Unix to send mail , I can help you .

~Sakthifire
Sponsored Links
    #5  
Old 08-21-2008
tahseen tahseen is offline
Registered User
 
Join Date: Aug 2008
Last Activity: 21 August 2008, 6:03 AM EDT
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
shell script

thanks for replying .yeah sure. any coding using any shell type is ok.
Sponsored Links
    #6  
Old 08-21-2008
sakthifire sakthifire is offline
Registered User
 
Join Date: Apr 2008
Last Activity: 16 May 2011, 12:10 AM EDT
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
#! /bin/ksh
#By Sakthifire
#TO send email
#regarding disk space

export FROM_ADDR="Sakthifire"
export TO_ADDR="emailid@mail.com"
CUR_DIR=/home/mail

send_mail()
{
for addr in $TO_ADDR
do
echo "From: $FROM_ADDR" > $CUR_DIR/mail.txt
echo "To: $TO_ADDR" >> $CUR_DIR/mail.txt
echo "Subject: Sending email">> $CUR_DIR/mail.txt
# here you can implement your logic to check the size of the folder
# redirect it to a mail.txt
echo "" >> $CUR_DIR/espmail.txt
echo "This is a automated email.Please don't reply to it ." >>$CUR_DIR/mail.txt
sendmail $addr < $CUR_DIR/espmail.txt
done
rm mail.txt
}
send_mail

----------------------------------------------------------------------------------------

Note : Please change the CUR_DIR , FROM_ADDR & TO_ADDR as per your need . You can have multiple sender email ids seperated by a space in TO_ADDR .

~Sakthifire

Last edited by sakthifire; 08-21-2008 at 05:52 AM..
Sponsored Links
    #7  
Old 08-21-2008
tahseen tahseen is offline
Registered User
 
Join Date: Aug 2008
Last Activity: 21 August 2008, 6:03 AM EDT
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
shell script

thank yous so much. Let me implement this!!!
thanks
tahseen
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
how to run a script using cron job and send the output as attachment via e-mail using unix vidhyaS Shell Programming and Scripting 8 06-09-2011 03:20 AM
unix script to check if rsh to box and send status mail bpm12 UNIX for Dummies Questions & Answers 1 10-09-2008 08:41 AM
Req the mail send from unix script Balamani UNIX for Dummies Questions & Answers 1 07-14-2008 09:02 AM
Script to send a mail in UNIX sudhi Shell Programming and Scripting 1 11-28-2006 07:53 AM
can not send mail from unix server to company/yahoo mail b5fnpct UNIX for Dummies Questions & Answers 5 11-22-2002 09:24 PM



All times are GMT -4. The time now is 05:52 AM.