Operating System - Linux
1753987 Members
4802 Online
108811 Solutions
New Discussion юеВ

Re: command mailx, adding hostname as subject

 
SOLVED
Go to solution
GB Tek
Valued Contributor

command mailx, adding hostname as subject

I have a basic script that I'd like to enhance by making sure the hostname gets added to the subject line of the email. Any suggestions?
The script I'm using:
ioscan -fnC fc > /tmp/pgb
ioscan -fnC lan >> /tmp/pgb
model >> /tmp/pgb
hostname >> /tmp/pgb
mailx me@mycompany.com < /tmp/pgb
rm -i /tmp/pgb
Ask and you shall receive
5 REPLIES 5
Patrick Wallek
Honored Contributor

Re: command mailx, adding hostname as subject

Have you looked into the '-s' option to mailx?

mailx -s "$(hostname) output" me@mycompany.com < /tmp/pgb

The use of $(hostname) will ensure portability if you use this script on more than one host. The $(hostname) executes the hostname command puts the output in its place.
Pete Randall
Outstanding Contributor

Re: command mailx, adding hostname as subject

Use "mailx -s".


Pete

Pete
John Kittel
Trusted Contributor
Solution

Re: command mailx, adding hostname as subject

ioscan -fnC fc > /tmp/pgb
ioscan -fnC lan >> /tmp/pgb
model >> /tmp/pgb
hostname >> /tmp/pgb
HOST=`hostname`
mailx -s ${HOST} me@mycompany.com < /tmp/pgb
rm -i /tmp/pgb
GB Tek
Valued Contributor

Re: command mailx, adding hostname as subject

Thanks John. That was the exact thing that made it work. Kudos!
Ask and you shall receive
GB Tek
Valued Contributor

Re: command mailx, adding hostname as subject

thx
Ask and you shall receive