- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: need a ping perl script looking for the Redire...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2006 12:28 PM
01-11-2006 12:28 PM
I need a perl script to send a mail if the Redirect Host (New nexthop)
will be different than 192.168.0.15
# ping 192.168.24.1
PING 192.168.24.1 (192.168.24.1) 56(84) bytes of data.
From 192.168.0.10: icmp_seq=1 Redirect Host(New nexthop: 192.168.0.15)
64 bytes from 192.168.24.1: icmp_seq=1 ttl=255 time=35.8 ms
64 bytes from 192.168.24.1: icmp_seq=2 ttl=255 time=37.7 ms
64 bytes from 192.168.24.1: icmp_seq=3 ttl=255 time=34.7 ms
64 bytes from 192.168.24.1: icmp_seq=4 ttl=255 time=36.2 ms
kind regards
chris
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2006 01:42 PM
01-11-2006 01:42 PM
Solutionone=$(ping xyz -n3|grep -i 'New nexthop' |awk -F : '{print $2}')
if [ ${one} ~= "192.168.0.15" ];then
echo "Nexthop is not \"192.168.0.15\""
else
echo "Nexthop is \"192.168.0.15\""
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2006 02:41 PM
01-11-2006 02:41 PM
Re: need a ping perl script looking for the Redirect Host (New nexthop)
Nitpicking.... but being a performance nutcase I can not stand activating two images where one is made to do the job.
Here grep + awk where awk is just made to select.
--- old ---
one=$(ping xyz -n3|grep -i 'New nexthop' |awk -F : '{print $2}')
--- suggested ---
one=$(ping xyz -n3| awk -F : '/New nexthop/ {print $2}')
of course both methods would have to deal with the ")" which is also picked up in $2.
In perl that would be, just picking up the address (untested)
nexthop=$(ping xyz -n3 | perl -ne 'print $1 if /hop:\s+([0-9.]+)/')
Of course you could also split (':')
But then in perl I would probably also do the ping and mail from the same script.
(again untested and unfinished...)
$good_next_hop = "192.168.0.15";
foreach (`ping xyz -n3`) {
next_hop = $1 if /hop:\s+([0-9.]+)/;
}
if ($next_hop .ne. $good_next_hop) {
mailx...
}
Cheers,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2006 10:39 AM
01-13-2006 10:39 AM
Re: need a ping perl script looking for the Redirect Host (New nexthop)
-------------------------------------------------------------------------------------------------------------
#!/usr/bin/perl -w
use strict;
use warnings;
my $good_next_hop = "192.168.0.15";
foreach (`ping 192.168.24.1 -n4`) {
next_hop = $1 if /hop:\s+([0-9.]+)/;
}
if ($next_hop .ne. $good_next_hop){
'echo "Message" | mailx -s "primary firewall is down" postmaster@domain.net'
}
-------------------------------------------------------------------------------------------------------------
# perl check.cgi
Can't modify constant item in scalar assignment at check.cgi line 10, near "$1 if"
Global symbol "$next_hop" requires explicit package name at check.cgi line 14.
syntax error at check.cgi line 14, near ".ne"
Execution of check.cgi aborted due to compilation errors.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2006 11:09 AM
01-13-2006 11:09 AM
Re: need a ping perl script looking for the Redirect Host (New nexthop)
Try this version of Hein's script:
#!/usr/bin/perl
use strict;
use warnings;
my $next_hop = "127.0.0.1"; #...in case nothing matches later
my $good_next_hop = "192.168.0.15";
foreach (`ping 192.168.0.15 -n4`) {
$next_hop = $1 if /hop:\s+([0-9.]+)/;
}
if ($next_hop ne $good_next_hop) {
`echo "Message" | mailx -s "primary firewall is down" postmaster@domain.net`
}
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2006 11:13 AM
01-13-2006 11:13 AM
Re: need a ping perl script looking for the Redirect Host (New nexthop)
Sorry, the 'foreach' loop had the wrong address:
#!/usr/bin/perl
use strict;
use warnings;
my $next_hop = "127.0.0.1"; #...in case nothing matches later
my $good_next_hop = "192.168.0.15";
foreach (`ping 192.168.24.1 -n4`) {
$next_hop = $1 if /hop:\s+([0-9.]+)/;
}
if ($next_hop ne $good_next_hop) {
`echo "Message" | mailx -s "primary firewall is down" root`
}
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2006 12:22 PM
01-13-2006 12:22 PM
Re: need a ping perl script looking for the Redirect Host (New nexthop)
this script seems to work without errors:
#!/usr/bin/perl -w
use strict;
use warnings;
my $mail = "postmaster\@domain.net";
my $next_hop = "127.0.0.1"; #...in case nothing matches later
my $good_next_hop = "192.168.0.15";
foreach (`ping 192.168.24.1 -c 4`) {
$next_hop = $1 if /hop:\s+([0-9.]+)/;
}
if ($next_hop ne $good_next_hop) {
`echo "primary firewall is down" | mailx -s "primary firewall is down" $mail`
}
exit;
but I have another big problem
if I do a ping for a first time I get following:
first ping:
# ping 192.168.24.1 -c 4
PING 192.168.24.1 (192.168.24.1) 56(84) bytes of data.
From 192.168.0.10: icmp_seq=1 Redirect Host(New nexthop: 192.168.0.15)
64 bytes from 192.168.24.1: icmp_seq=1 ttl=255 time=37.8 ms
64 bytes from 192.168.24.1: icmp_seq=2 ttl=255 time=33.6 ms
64 bytes from 192.168.24.1: icmp_seq=3 ttl=255 time=35.1 ms
64 bytes from 192.168.24.1: icmp_seq=4 ttl=255 time=37.8 ms
--- 192.168.24.1 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3002ms
rtt min/avg/max/mdev = 33.658/324.144/37.895/1.831 ms
second ping:
# ping 192.168.24.1 -c 4
PING 192.168.24.1 (192.168.24.1) 56(84) bytes of data.
64 bytes from 192.168.24.1: icmp_seq=1 ttl=255 time=34.7 ms
64 bytes from 192.168.24.1: icmp_seq=2 ttl=255 time=36.2 ms
64 bytes from 192.168.24.1: icmp_seq=3 ttl=255 time=37.1 ms
64 bytes from 192.168.24.1: icmp_seq=4 ttl=255 time=34.3 ms
--- 192.168.24.1 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3003ms
rtt min/avg/max/mdev = 34.393/35.641/37.153/1.152 ms
this script will be scheduled every half hour
first ping looks for the next hop but following next one next it doesn't.
now I will get many wrong mails.
knows someone any ping command to look every time for the next hop ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2006 05:35 AM
01-23-2006 05:35 AM
Re: need a ping perl script looking for the Redirect Host (New nexthop)
seems to solve my problem, but howto put this command before ping to this perl program ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2006 05:44 AM
01-23-2006 05:44 AM
Re: need a ping perl script looking for the Redirect Host (New nexthop)
You can run an external command in perl serveral ways. In this case, probably the easiest way is to enclose it in backticks where you want to place it. End the line with a semicolon, of course.
...
`ip route flush cache`;
foreach (`ping 192.168.24.1 -c 4`) {
Regards!
...JRF...