Script to ping every hour and email failure
Clash Royale CLAN TAG#URR8PPP
up vote
-1
down vote
favorite
I'm trying to write a shell script to ping 5 hosts I have once every 1 hour and if it receives any failure from any of those hosts, it sends an email alert with the results from this failing ping.
shell scripting ping
add a comment |Â
up vote
-1
down vote
favorite
I'm trying to write a shell script to ping 5 hosts I have once every 1 hour and if it receives any failure from any of those hosts, it sends an email alert with the results from this failing ping.
shell scripting ping
add a comment |Â
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I'm trying to write a shell script to ping 5 hosts I have once every 1 hour and if it receives any failure from any of those hosts, it sends an email alert with the results from this failing ping.
shell scripting ping
I'm trying to write a shell script to ping 5 hosts I have once every 1 hour and if it receives any failure from any of those hosts, it sends an email alert with the results from this failing ping.
shell scripting ping
shell scripting ping
edited Feb 19 '17 at 12:56
Jeff Schaller
33.3k850112
33.3k850112
asked Feb 17 '17 at 2:39
Katkota
414
414
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
6
down vote
accepted
Something like this should work:
#!/bin/bash
ping_targets="server1 server2 server3 server4 server5"
failed_hosts=""
for i in $ping_targets
do
ping -c 1 $i > /dev/null
if [ $? -ne 0 ]; then
if [ "$failed_hosts" == "" ]; then
failed_hosts="$i"
else
failed_hosts="$failed_hosts, $i"
fi
fi
done
if [ "$failed_hosts" != "" ]; then
echo $failed_hosts| mailx -s "Failed ping targets" email@domain
fi
Put it in a script, change the hostnames and email address, make it executable, and add an entry to cron so it runs once per hour.
Thank you very much.. I had to make some modification but your script worked great!!
â Katkota
Feb 17 '17 at 22:15
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
6
down vote
accepted
Something like this should work:
#!/bin/bash
ping_targets="server1 server2 server3 server4 server5"
failed_hosts=""
for i in $ping_targets
do
ping -c 1 $i > /dev/null
if [ $? -ne 0 ]; then
if [ "$failed_hosts" == "" ]; then
failed_hosts="$i"
else
failed_hosts="$failed_hosts, $i"
fi
fi
done
if [ "$failed_hosts" != "" ]; then
echo $failed_hosts| mailx -s "Failed ping targets" email@domain
fi
Put it in a script, change the hostnames and email address, make it executable, and add an entry to cron so it runs once per hour.
Thank you very much.. I had to make some modification but your script worked great!!
â Katkota
Feb 17 '17 at 22:15
add a comment |Â
up vote
6
down vote
accepted
Something like this should work:
#!/bin/bash
ping_targets="server1 server2 server3 server4 server5"
failed_hosts=""
for i in $ping_targets
do
ping -c 1 $i > /dev/null
if [ $? -ne 0 ]; then
if [ "$failed_hosts" == "" ]; then
failed_hosts="$i"
else
failed_hosts="$failed_hosts, $i"
fi
fi
done
if [ "$failed_hosts" != "" ]; then
echo $failed_hosts| mailx -s "Failed ping targets" email@domain
fi
Put it in a script, change the hostnames and email address, make it executable, and add an entry to cron so it runs once per hour.
Thank you very much.. I had to make some modification but your script worked great!!
â Katkota
Feb 17 '17 at 22:15
add a comment |Â
up vote
6
down vote
accepted
up vote
6
down vote
accepted
Something like this should work:
#!/bin/bash
ping_targets="server1 server2 server3 server4 server5"
failed_hosts=""
for i in $ping_targets
do
ping -c 1 $i > /dev/null
if [ $? -ne 0 ]; then
if [ "$failed_hosts" == "" ]; then
failed_hosts="$i"
else
failed_hosts="$failed_hosts, $i"
fi
fi
done
if [ "$failed_hosts" != "" ]; then
echo $failed_hosts| mailx -s "Failed ping targets" email@domain
fi
Put it in a script, change the hostnames and email address, make it executable, and add an entry to cron so it runs once per hour.
Something like this should work:
#!/bin/bash
ping_targets="server1 server2 server3 server4 server5"
failed_hosts=""
for i in $ping_targets
do
ping -c 1 $i > /dev/null
if [ $? -ne 0 ]; then
if [ "$failed_hosts" == "" ]; then
failed_hosts="$i"
else
failed_hosts="$failed_hosts, $i"
fi
fi
done
if [ "$failed_hosts" != "" ]; then
echo $failed_hosts| mailx -s "Failed ping targets" email@domain
fi
Put it in a script, change the hostnames and email address, make it executable, and add an entry to cron so it runs once per hour.
answered Feb 17 '17 at 4:32
Warwick
1,322715
1,322715
Thank you very much.. I had to make some modification but your script worked great!!
â Katkota
Feb 17 '17 at 22:15
add a comment |Â
Thank you very much.. I had to make some modification but your script worked great!!
â Katkota
Feb 17 '17 at 22:15
Thank you very much.. I had to make some modification but your script worked great!!
â Katkota
Feb 17 '17 at 22:15
Thank you very much.. I had to make some modification but your script worked great!!
â Katkota
Feb 17 '17 at 22:15
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f345630%2fscript-to-ping-every-hour-and-email-failure%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password