On Wed, Jul 16, 2003 at 03:04:55PM +0800, Jun Tanamal wrote:
> >ping -c 2 <ip-address-here>
> >
> >if [ ! "$?" = 0 ]; then
In Bash, $? expands to the status of the most recent foreground command,
in this case, ping. For more information, read the "Special Parameters"
section of "PARAMETERS" in the bash(1) manual page.
The brackets in if are for conditions, and are equivalent to the test
command. Read the test(1) manual page for more information. I don't know
if the brackets are universal for sh-like shells, or if they're
bashisms.
> and what syntax is for the mail command? (I'm confused in #man mail)
This should work:
$ echo "Some message..." | mail root -s "Ping Test"
You may want to note, though, that cron by default will send all output
as an email to the owner of the cron job unless otherwise overriden by
MAILTO, so you shouldn't need to do the emailling yourself. For more
information, read the crontab(5) manual page.
For scripting use, I highly recommend fping instead of ping. The
fping(8) manual page even has a nice Perl script for what you want to
do. It brings it further by supporting multiple hosts that you want to
test. This can be rewritten in Bash or Python, but this is the example
from the manual page so here goes:
#!/usr/bin/perl
require 'open2.pl';
$MAILTO = "root";
$pid = &open2("OUTPUT","INPUT","/usr/local/bin/fping -u");
@check=("slapshot","foo","foobar");
foreach(@check) { print INPUT "$_\n"; }
close(INPUT);
@output=<OUTPUT>;
if ($#output != -1) {
chop($date=`date`);
open(MAIL,"|mail -s 'unreachable systems' $MAILTO");
print MAIL "\nThe following systems are unreachable as of: $date\n\n";
print MAIL @output;
close MAIL;
}
--> Jijo
--
Federico Sevilla III : http://jijo.free.net.ph : When we speak of free
Network Administrator : The Leather Collection, Inc. : software we refer to
GnuPG Key ID : 0x93B746BE : freedom, not price.
--
Philippine Linux Users' Group (PLUG) Mailing List
[EMAIL PROTECTED] (#PLUG @ irc.free.net.ph)
Official Website: http://plug.linux.org.ph
Searchable Archives: http://marc.free.net.ph
.
To leave, go to http://lists.q-linux.com/mailman/listinfo/plug
.
Are you a Linux newbie? To join the newbie list, go to
http://lists.q-linux.com/mailman/listinfo/ph-linux-newbie