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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
03-08-2006, 11:18 PM
|
#1
|
Member
Registered: Oct 2005
Posts: 32
Rep:
|
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
====================
|
|
|
03-09-2006, 02:12 AM
|
#2
|
LQ Guru
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,223
|
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'
|
|
|
03-09-2006, 02:25 AM
|
#3
|
Member
Registered: Oct 2005
Posts: 32
Original Poster
Rep:
|
Hello ,
Thanks for the post.
I tried with -r option, it is saying invalid option
Thanks,
Srikanth
|
|
|
03-09-2006, 02:28 AM
|
#4
|
Member
Registered: Oct 2005
Posts: 32
Original Poster
Rep:
|
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
|
|
|
03-09-2006, 02:48 AM
|
#5
|
LQ Guru
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,223
|
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.
|
|
|
03-09-2006, 02:56 AM
|
#6
|
Member
Registered: Oct 2005
Posts: 32
Original Poster
Rep:
|
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
|
|
|
03-09-2006, 02:59 AM
|
#7
|
Senior Member
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,639
Rep: 
|
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...
|
|
|
03-09-2006, 03:10 AM
|
#8
|
Member
Registered: Oct 2005
Posts: 32
Original Poster
Rep:
|
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
|
|
|
03-09-2006, 03:14 AM
|
#9
|
Member
Registered: Oct 2004
Location: Germany
Distribution: Debian
Posts: 274
Rep:
|
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 ")
|
|
|
03-09-2006, 03:59 AM
|
#10
|
Member
Registered: Oct 2005
Posts: 32
Original Poster
Rep:
|
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
|
|
|
03-09-2006, 04:30 AM
|
#11
|
LQ Newbie
Registered: Mar 2006
Posts: 1
Rep:
|
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
====================
|
|
|
|
03-09-2006, 04:43 AM
|
#12
|
Member
Registered: Oct 2004
Location: Germany
Distribution: Debian
Posts: 274
Rep:
|
fixed my script above... (wrong quoting char in line 41)
|
|
|
All times are GMT -5. The time now is 03:01 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|