The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Mac OS X 10.5: Can receive email, but not send email iBot OS X Support RSS 0 10-13-2008 10:20 PM
Mac OS X 10.5: Can receive email, but not send email iBot OS X Support RSS 0 09-27-2008 07:12 AM
blocking the commands result rag84dec Shell Programming and Scripting 2 03-27-2008 01:37 AM
Send email where # is in the email address - Using Unix jingi1234 UNIX for Dummies Questions & Answers 1 05-23-2005 11:23 AM
Unable to send eMail from a UNIX-Host ( using mailx ) to a Outlook-email-addres(Win) Vetrivela UNIX for Advanced & Expert Users 2 02-15-2005 10:43 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-23-2008
varu0612 varu0612 is offline
Registered User
  
 

Join Date: Oct 2008
Location: uk
Posts: 5
Question Send one email with output result from 2 commands

Hi,

i want to create a script which should do the following:

1) ping the remote servers and email the hosts which are down
2) netstat on port x on 2 server and email the result too.

I want both results to be sent in the same email.

I have few ideas but i can't finish it.

Here is my idea:
#!/bin/bash
HOSTS="host1 host2"

# email report

SUBJECT="Ping failed"
EMAILID="jon@abc.com"

for myHost in $HOSTS
do
jj=$(ping $myHost -w2 | awk '/received/ {print $4}')
if [ $jj -eq 0 ]
then
# 100% failed
echo "Host : $myHost is down (ping failed) at $(date)" | mail -s $SUBJECT" $EMAILID
fi
done

#check netstat

net=$(netstat -na|grep 5005)

if ($net)
then
echo $net
else
ssh host2 $net
echo "The app is running on $HOST and is connected on $net"| mail -s "$SUBJECT" $EMAILID

My issues are:

1) i don't know how to send in one mail both result
2) i don't know how to check the netstat command on if ...then

Many thanks for your help
  #2 (permalink)  
Old 12-23-2008
broli's Avatar
broli broli is offline
Registered User
  
 

Join Date: Dec 2007
Location: Argentina
Posts: 215
(echo "first echo"; echo "second echo") | mailx -s test jon@abc.com
  #3 (permalink)  
Old 12-23-2008
Lakris Lakris is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 246
Hi,
You can append all the output into one file and then send it with
cat /tmp/resultfile | mail -s "$SUBJECT" $EMAILID
and then remove it afterwards.

/Lakris
  #4 (permalink)  
Old 01-16-2009
varu0612 varu0612 is offline
Registered User
  
 

Join Date: Oct 2008
Location: uk
Posts: 5
thanks guys
  #5 (permalink)  
Old 01-16-2009
Rhije Rhije is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 103
Just a note, you can redirect the output of an entire block in bash to whatever you want.. Such as..

Code:
#!/bin/bash
{

# code here

} > somefile.txt
Of course, it doesnt have to go to somefile.txt, it can go wherever.
Closed Thread

Bookmarks

Tags
ping, ping port, port, port ping

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:05 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0