Operating System - HP-UX
1752587 Members
3931 Online
108788 Solutions
New Discussion юеВ

Re: Telnet email: how to include a file content in an email

 
molo1
Occasional Contributor

Telnet email: how to include a file content in an email

Hi,

I wrote a HP-UX script. It used telnet to send email.

Although it works, I couldn't include a text file's content in the email I sent.

I have tried and AIX example but it didn't work.

Can you help me?

 

AIX telnet example:

EMAILSENDER="xxx@1234.com
EMAILRECEIVER1="yyy@1234.com"
EMAILRECEIVER2="zzz@1234.com"

REPORTCONTENT=`cat /u02/db_script/outlog/mon_block.log`

telnet relay.1234.com 25 << EOF
helo
mail from:$EMAILSENDER
rcpt to:$EMAILRECEIVER1
rcpt to:$EMAILRECEIVER2
data
From: $EMAILSENDER
To: $EMAILRECEIVER1
To: $EMAILRECEIVER2
Subject: POS Oracle Blocking session exists

$REPORTCONTENT
.
quit
EOF

 However, unluckily, I couldn't use the "$REPORTCONTENT" method to display a text file's content in an email by telnet.

Can you help me?

Thanks a lot. 

8 REPLIES 8
Dennis Handly
Acclaimed Contributor

Re: Telnet email: how to include a file content in an email

> Although it works, I couldn't include a text file's content in the email I sent.

 

What do you get instead?

Why not just use mailx?

If you replace "telnet relay.1234.com 25" by "cat" you should see what telnet is getting.

Steven Schweda
Honored Contributor

Re: Telnet email: how to include a file content in an email

> I have tried and AIX example but it didn't work.

   Where did you find your "AIX example"?

> $REPORTCONTENT

   I don't see how this could possibly work.  Is the AIX Telnet client
scanning what I type, looking for $<var_name>, and then sending file
contents instead of what I typed?  I doubt it.

> What do you get instead?

   I know nothing, but I'd bet a small sum on "$REPORTCONTENT".

Dennis Handly
Acclaimed Contributor

Re: Telnet email: how to include a file content in an email

>   I don't see how this could possibly work.

 

Why not?  This is a here doc and the value of the variable should be substituted.

Though I would use this instead: $( < /u02/db_script/outlog/mon_block.log)

Steven Schweda
Honored Contributor

Re: Telnet email: how to include a file content in an email

> Why not?  This is a here doc [...]

   Thanks for reading it to me.  I must have been even less alert than
usual when I read it for myself.  Sigh.

molo1
Occasional Contributor

Re: Telnet email: how to include a file content in an email

Hi all,

mailx doesn't wrok in my DEV and UAT but only production, so, in order to standardize the source code, I use telnet.

I just simplily to want: write a script and put it into crontab, it will grep our SAP Oracle alert log regularly, eg. per hour, then, once there is an ORA message in the alert log, it will send emails to our team.

The email will include all the ORA lines from the alert log. But I couldn't make it out.

My script:

> cat greporaalert.sh

#!/bin/sh

EMAILSENDER="it_dba@1234.com"
EMAILRECEIVER1="it_dba@1234.com"
EMAILRECEIVER2="it_manager@1234.com"

REPORTCONTENT='cat /.../ORAmesg.log'

grep "ORA-" /.../alert_DEV.log > /oracle/DEV/ORAmesg.log
count=$(cat /.../ORAmesg.log | wc -l)

if [ "$count" != 0 ]
then
telnet relay.1234.com 25 << EOF
helo
mail from: $EMAILSENDER
rcpt to: $EMAILRECEIVER1
rcpt to: $EMAILRECEIVER2
data
From: $EMAILSENDER
To: $EMAILRECEIVER1
To: $EMAILRECEIVER2
Subject: [Alert] ORA message is found

ORA message is found.

Please read the alert log for details:

/..../alert_DEV.log

$REPORTCONTENT
.
quit
EOF
fi

 It only displays:

ORA message is found.

Please read the alert log for details:

/..../alert_DEV.log

cat /.../ORAmesg.log

 

It just displayed the command: cat /.../ORAmesg.log but not the content of the ORAmesg.log file.

Any idea?

Bill Hassell
Honored Contributor

Re: Telnet email: how to include a file content in an email

Try this to display the ORAmesg.log directly rather than using REPORTLOG variable:

 

$(<$ORAmesg.log)

 

 



Bill Hassell, sysadmin
Steven Schweda
Honored Contributor

Re: Telnet email: how to include a file content in an email

> It only displays:
> [...]
> cat /.../ORAmesg.log

   That's a clue.

> REPORTCONTENT='cat /.../ORAmesg.log'

      echo $REPORTCONTENT

   You seem to be using apostrophes (') where you want back-ticks/grave
accents (`).  Or, you might want both, depending on how much stuff you
want to store in that shell variable.

> $(<$ORAmesg.log)

   One advantage of the "$()" notation is that it's visually clearer
(and less font-dependent) than "``" (v. "''").

Dennis Handly
Acclaimed Contributor

Re: Telnet email: how to include a file content in an email

   > One advantage of the "$()" notation is that it's visually clearer

 

And most important of all, you can nest them.

 

@molo1: mailx doesn't work in my DEV and UAT but only production

 

Why not?  You don't have sendmail working?

 

> REPORTCONTENT='cat /.../ORAmesg.log'

 

This is NOT what you had in the first post.  You had `` and not ''.

 

> count=$(cat /.../ORAmesg.log | wc -l)

 

Remove the evil cat:

count=$(wc -l < ./.../ORAmesg.log)

But better yet, remove the wc(1) completely:

if [ -s ./.../ORAmesg.log ]; then