LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-08-2006, 11:18 PM   #1
srikanthrao_d
Member
 
Registered: Oct 2005
Posts: 32

Rep: Reputation: 15
Help on Script


Hi All,

I am using one script where it will ping to servers and if any thing is down it will send mail, I used mail but mail I can not mention from address so I used sendmail. In sendmail I can not mention the subject, please help me how to mention the subject in the sendmail. I am posting script also.

Thanks,
Srikanth

==========script=============

[root@ss-mail ~]# cat ping
#!/bin/bash
#This script pings all the servers\
hosts=/root/hostfiles
for str in `cat $hosts`
do
ping -c 1 $str >> output_file 2>&1
if [ $? -eq 0 ]
then
echo $str is up
else
echo $str is down | /usr/sbin/sendmail -r 'sysadmin@mm.com' 'sysadmin@mm.com'
fi
done
rm -f output_file
====================
 
Old 03-09-2006, 02:12 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,223
Blog Entries: 1

Rep: Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076
Quote:
echo $str is down | /usr/sbin/sendmail -r 'sysadmin@mm.com' 'sysadmin@mm.com'
mail works just fine usnig this:
Code:
echo $str is down | /usr/bin/mail -s 'Down' -r 'sysadmin@mm.com' 'sysadmin@mm.com'
 
Old 03-09-2006, 02:25 AM   #3
srikanthrao_d
Member
 
Registered: Oct 2005
Posts: 32

Original Poster
Rep: Reputation: 15
Hello ,

Thanks for the post.

I tried with -r option, it is saying invalid option

Thanks,
Srikanth
 
Old 03-09-2006, 02:28 AM   #4
srikanthrao_d
Member
 
Registered: Oct 2005
Posts: 32

Original Poster
Rep: Reputation: 15
I tried with removing -r option, but i did not get from address.here i need from address and subject also very important.

Thanks,
Srikanth
 
Old 03-09-2006, 02:48 AM   #5
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,223
Blog Entries: 1

Rep: Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076
It should work!!
Run
Code:
ls -l /usr/bin/mail
to see if it's a symlink to mutt or something, because mutt does not have the -r option. You can use mailx or nail (which is the actual mail or mailx command in Slackware for example) to see if it helps.
 
Old 03-09-2006, 02:56 AM   #6
srikanthrao_d
Member
 
Registered: Oct 2005
Posts: 32

Original Poster
Rep: Reputation: 15
Hello Sir,

I did not find mail on /usr/bin/. I do not find other mutt also
===========================
[root@hyd-backup ~]# ls -l /usr/bin/ma
mac2unix mail-files makecode make_wagon_desc
macbinary mail.local makedb makewhatis
macptopbm mailq make_driver_db_cups man
macsave mailq.exim make_driver_db_lpr man2html
macstream mailq.postfix make_encmap manpath
macunpack mailq.sendmail makeindex manweb
macusers mailsettings makeinfo mapscrn
mag mailshar makekdewidgets matchpathcon
magicdev mailstat makemap mattrib
magicfilter-t mailutil makempx
magnifier mailutime makempy
mahjongg make makeobj
=============================================

i am using FC3 here. Please help me to proceed further

Thanks
 
Old 03-09-2006, 02:59 AM   #7
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,639

Rep: Reputation: Disabled
Why don't you try "locate mail" to see where what resides? I notice that your /usr/bin doesn't contains neither mail nor mutt...
 
Old 03-09-2006, 03:10 AM   #8
srikanthrao_d
Member
 
Registered: Oct 2005
Posts: 32

Original Poster
Rep: Reputation: 15
I found mail in /bin/mail

but when i did not see mut there i can see only mail there

when i excute with it is giving this error

[root@ss ~]# ./ping
10.191.40.254 is up
10.191.40.253 is up
10.191.40.252 is up
10.0.1.21 is up
10.0.1.22 is up
10.0.1.32 is up
10.91.0.254 is up
10.91.0.253 is up
10.91.0.252 is up
10.91.0.249 is up
/bin/mail: invalid option -- r
Usage: mail [-iInv] [-s subject] [-c cc-addr] [-b bcc-addr] to-addr ...
[- sendmail-options ...]
mail [-iInNv] -f [name]
mail [-iInNv] [-u user]
===========

locate results

[root@ss ~]# ls -l /bin/m
mail mkdir mknod mktemp more mount mt mv
[root@ss ~]# ls -l /bin/m

Thanks,
Srikanth
 
Old 03-09-2006, 03:14 AM   #9
doc.nice
Member
 
Registered: Oct 2004
Location: Germany
Distribution: Debian
Posts: 274

Rep: Reputation: 34
man mail is your friend...
using -a you can add an "From:"-Header. this of course doesn't send your messsage
from this account, but shows this as the sender. Use "Reply-To:" for fixing the
answer-function...

Code:
#!/bin/bash

###
### This script pings all the servers
### in the file defined in $outfile
### and sends mail if at least one
### host does not respond.
###
### written by Florian Harbich (doc.nice on linuxquestions.org,
### based on code from linuxquestions.org
### user srikanthrao_d
### in thread 423027 ("Help on script")
### no rights reserved.
### Use it as you like
###

# file with hosts to ping (one per line)
hosts='/root/hostfiles'

# temporary ping output
outfile='/tmp/output_file'

downhosts=''

if [ ! -r $hosts ]; then
  echo "Hosts list ($hosts) ist not readable! command aborted." >&2
  exit 1
fi

for hname in `cat $hosts`; do
  ping -c 1 $hname >> $outfile 2>&1
  if [ $? -eq 0 ]; then
    echo "$hname is up"
  else
    echo "$hname is down" >&2
    downhosts="$downhosts, $hname"
  fi
done

if [ "$downhosts" ]; then
  mail -s 'System down' -a 'From: sysadmin@mm.com' -a 'Reply-To: sysadmin@mm.com' 'sysadmin@mm.com' <<-EOF
    The System $str does not respond to ping probes.

    Please check online status.

    Ping log follows:
    --SNIP--
    $(cat $outfile)
    --SNAP--

    -- 
    This message was automatically generated by the ping script
    at $(date) on $(hostname)
  EOF
fi
rm -f $outfile >/dev/null 2>&1
Hope this helps...
Florian

Last edited by doc.nice; 03-09-2006 at 04:42 AM. Reason: line 41: Reply-To had wrong quoting-char (" instead of ")
 
Old 03-09-2006, 03:59 AM   #10
srikanthrao_d
Member
 
Registered: Oct 2005
Posts: 32

Original Poster
Rep: Reputation: 15
Hi

Thanks a lot for your help

i do not have that much idea on script when i am trying to excute your given script i am getting some error. Please let me know what are the changes i need to do

thanks
srikanth

Errors

=========

./man: line 41: unexpected EOF while looking for matching `"'
./man: line 58: syntax error: unexpected end of file
 
Old 03-09-2006, 04:30 AM   #11
sseetharaman
LQ Newbie
 
Registered: Mar 2006
Posts: 1

Rep: Reputation: 0
Hi Srikanth,

You can create file with entries like

Subject: Ping Problem
Some content here

and feed input for sendmail

sendmail -r 'sysadmin@mm.com' 'sysadmin@mm.com' < <file_name_u_create>

thx
sseetharaman



Quote:
Originally Posted by srikanthrao_d
Hi All,

I am using one script where it will ping to servers and if any thing is down it will send mail, I used mail but mail I can not mention from address so I used sendmail. In sendmail I can not mention the subject, please help me how to mention the subject in the sendmail. I am posting script also.

Thanks,
Srikanth

==========script=============

[root@ss-mail ~]# cat ping
#!/bin/bash
#This script pings all the servers\
hosts=/root/hostfiles
for str in `cat $hosts`
do
ping -c 1 $str >> output_file 2>&1
if [ $? -eq 0 ]
then
echo $str is up
else
echo $str is down | /usr/sbin/sendmail -r 'sysadmin@mm.com' 'sysadmin@mm.com'
fi
done
rm -f output_file
====================
 
Old 03-09-2006, 04:43 AM   #12
doc.nice
Member
 
Registered: Oct 2004
Location: Germany
Distribution: Debian
Posts: 274

Rep: Reputation: 34
fixed my script above... (wrong quoting char in line 41)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Iptables (with masq) troubleshooting, very simple script attached script and logs. xinu Linux - Networking 13 11-01-2007 04:19 AM
python cgi script and premature end of script headers Neruocomp Programming 1 07-28-2005 11:43 AM
How to start a Tcl/Tk script by simply invoking the script file itself ? cyu021 Programming 2 10-10-2004 11:00 AM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
linux 9 and java script error - premature end of script header sibil Linux - Newbie 0 01-06-2004 04:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration