adding hostname and date in subject of the mail


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting adding hostname and date in subject of the mail
# 1  
Old 05-13-2011
adding hostname and date in subject of the mail

Hi Team,
I coded my code to send mail to some reciepents with subject and date.
Can somebody suggest me how to add host name to subject ? and the below code is correct for date ?

my aim is to send mail with "subject in < hostname> on <date>".When i execute this script on my server its hung up any idea where to change ?


Code:
#======================================================================================
#  Program          : xxx
#  Description      : xxx
#  Date             : xxx
#  Version          : 1.0
#  Usage            : xxxx.sh > xxx.out
#=====================================================================================
SUBJECT="xxxx "
DATE=`date`
echo `date` > FS.out
echo "\n-------------------$SUBJECT ---------------------\n">>FS.out
df -g /db2/db2inst1/  /db2/db2inst2/  /db2/db2inst3/ >> FS.out

if [ $? -ne 0 ] ; then
    echo `date` > FS.out
    echo "Error in df command ...Please check the Crontab entry and script " >> FS.out
exit 1
fi

echo "\n-----------------$SUBJECT  ------------------------\n">>FS.out
#SEND the FS space details to the below reciepents.

mail -s "$SUBJECT on $DATE" "xxxxx@gmail.com" -r xxx.gmail.com
< FS.out  >mail.log

if [ $? -ne 0 ] ; then
       echo "Error in Mailing to the Team  ...Please check "
       exit 1
fi
    rm FS.out

echo "sucessfully you have mailed"
~

Regards
# 2  
Old 05-13-2011
host name can be take by executing
Code:
hostname

command

Code:
HOST=`hostname`

---------- Post updated at 02:30 PM ---------- Previous update was at 02:28 PM ----------

If you are using your office or home network to send mails to gmail, then I don't think it will work.

Because the current server IP will go for NAT and will go as public IP from your ISP. I don't think it will work. I may bot be correct.

Instead try to send mails inside your own domain.

Last edited by kumaran_5555; 05-13-2011 at 06:09 AM..
# 3  
Old 05-13-2011
do you have any sample code for this ? my script has hang now .it was running from my machine when i ran it yesterday.
# 4  
Old 05-13-2011
Code:
cgi@tioman> (/home/cgi/c_test) $
cgi@tioman> (/home/cgi/c_test) $ mail -s "Test2" senthilkumaran.rajagopalan@billing.com
Hello testing mail
last line
.
Cc:
cgi@tioman> (/home/cgi/c_test) $
cgi@tioman> (/home/cgi/c_test) $

This is just using the prompt without using scripts.

Try to send a simple mail from prompt to check the connectivity and later you can do it using script.

If you are using crontab, make sure you absolute paths for log files and eveything.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Adding Attachments to mail

Hi, I need to send a mail with html code in body and an attachment along with the body and subject. The html code must display a table with data in it in the mail. I have tried the 'sendmail' command, but I am am able to display the table in the mail and unable to attach an attachment. ... (5 Replies)
Discussion started by: Durga Prasad NK
5 Replies

2. Shell Programming and Scripting

Adding hostname on the output

// AIX 6.1 pcmpath query device |awk 'BEGIN{print "TYPE\tDEVICE NAME\tSERIAL\tSIZE"} /DEVICE/ {disk=$5 printf "%s\t", $7 printf "%s\t", disk getline; printf "%s\t", substr($2, length($2)-3) ("bootinfo -s "... (2 Replies)
Discussion started by: Daniel Gate
2 Replies

3. UNIX for Dummies Questions & Answers

Adding hours and minutes to current date (Only to date not to time)

Hi, I want to add some hours and minutes to the current date. For example, if the current date is "July 16, 2012 15:20", i want to add 5 hours 30 minutes to "July 16, 2012 00:00" not to "July 16, 2012 15:20". Please help. Thanks! (4 Replies)
Discussion started by: manojgarg
4 Replies

4. UNIX for Advanced & Expert Users

AIX - Sendmail - add hostname to subject of outgoing mail

Hello, I'm configuring sendmail on an AIX 7.1 server (bos.net.tcp.client 7.1.1.15). I've gotten sendmail to send mail through our Novell GroupWise server, so that mail from a user on the server appears to come from their GroupWise account, and replies to the email would go to their GroupWise... (0 Replies)
Discussion started by: eyebeam
0 Replies

5. Shell Programming and Scripting

Adding days to system date then compare to a date

Hi! I am trying to read a file and every line has a specific date as one of its fields. I want to take that date and compare it to the date today plus 6 days. while read line do date=substr($line, $datepos, 8) #date is expected to be YYYYMMDD if ; then ...proceed commands ... (1 Reply)
Discussion started by: kokoro
1 Replies

6. Shell Programming and Scripting

Find files having todays date and hostname in its name.

Hello, I am quite new to unix/shell and want to write a script using bash which will process the files. Basically i want to search files having name as "date+hostname+somestring.out" i am using below variables and then will use them in find command :- TODAY_DATE=$('date +%d')... (5 Replies)
Discussion started by: apm
5 Replies

7. Shell Programming and Scripting

Adding date to the subject using mailx

Hi , I want to add date to the subject of the email. I am using mail and used -s "SQL Loader was not able to load enid on `date` due to data error" But it didnt work. can any one help me ?? Thanks Sithara (1 Reply)
Discussion started by: sithara
1 Replies

8. UNIX for Advanced & Expert Users

date need to be add in the subject of the mail.

Hi Am fetching a weekly report pf data..once i fetched the data i need a sent report by mail. In the subject of that mail i want to sent a message like.. SUBJECT :The report had been fetched from (01/12/08 to 07/12/08). I need to send a report like this every week with that particular... (2 Replies)
Discussion started by: bobprabhu
2 Replies

9. Solaris

Problem sending mail after IP/hostname change

Hello, I had to replace my Solaris 10 workstation with the other one because of hardware issues. I need to configure the new WS with the same configuration. It looked like it was using DHCP before and I was able to send mail with mailx command. Since old HW used static IP I have disabled DHCP and... (8 Replies)
Discussion started by: pn8830
8 Replies

10. UNIX for Dummies Questions & Answers

How to set Subject in 'mail' ?

Hi, I am trying to send some file to some mail ids using mail command in UNIX. Now the issue is I am not able to find how to add "Subject text" to the command. So I am using command like "mail abc@yahoo.com < file_name" Now if I use simple mail command I can set subject text by using... (2 Replies)
Discussion started by: hkapil
2 Replies
Login or Register to Ask a Question