#!/bin/bash
WGET="/usr/bin/wget"
$WGET -q --tries=10 --timeout=5 http://www.google.com -O /tmp/index.google &> /dev/null
if [ ! -s /tmp/index.google ];then
echo "no"
else
echo "yes"
fi
It tries to download google page within 5 seconds
returns 'yes' if google page index is downloaded
else return 'no'
Linux administration , Unix administration , Vmware Vsphere administration , Oracle DBA ,apache, backup, dhcp, dns, kvm, xen, kernel, ldap, kvm, monitoring, ticketing, networking, Mail servers, SAN,troubleshooting
Labels
- Amanda (2)
- Ansible (2)
- Answer these Questions (2)
- antivirus (2)
- apache (3)
- Bash (16)
- Chef (3)
- Citrix (2)
- clusters (2)
- Concept (22)
- DatabaseAdminstration (11)
- DevOps (1)
- dhcp (2)
- Downloads (3)
- ELK (1)
- ELK stack (1)
- encryption (1)
- Free trainings (1)
- Frequently Used Commands (46)
- FTP (1)
- git (1)
- gpg (2)
- Hardware (1)
- httpd (2)
- Interview Questions (53)
- iptables (1)
- IT NEWS (3)
- java (1)
- kibana (2)
- knife (1)
- KVM (2)
- linux (17)
- Linux installations (22)
- Linux Jobs (4)
- Linux Links (2)
- logstash (1)
- Mac (1)
- MediaWiki (1)
- MySql (2)
- Nagios (2)
- Networking (3)
- open Nebula (5)
- Open Source tools (12)
- OpenNMS (1)
- openSSL (1)
- Oracle on Linux (5)
- Performance Monitoring (1)
- php (1)
- postfix (1)
- postgres (1)
- postgres-XL (1)
- Product Reviews (1)
- Python (2)
- rssh (1)
- Samba (2)
- Scripting (16)
- security (4)
- selinux (1)
- Server (1)
- SFTP (1)
- Social Awareness (1)
- Solaris (1)
- SSL (1)
- svn (1)
- TCP/IP (1)
- Technology (1)
- Tips and Tricks (32)
- Training and materials (8)
- Troubleshooting (6)
- Ubuntu (18)
- unix (1)
- virtualization (17)
- Vmware (25)
- Vyatta (1)
- windows7 (1)
- xml (1)
5 comments:
Good idea.
But that will use some bandwidth. Will it be possible to have a "ping" solution?
Like pinging a website 10 times, and see how many packets reached the target?
JM
the best one
if eval "ping -c 1 www.google.com"; then
echo "We've got internet"
else
echo "No internet available"
fi
Nope the last one won't work so well. Because even if you don't have internet access the script will show that you have. I think ping in some way will leave exit status 0 even if it cant ping the host. Strange but seems to be true.
Sorry, scratch my last reply. Of course it seems to work. The thing was that even thou I hade switched my network connection of the script said that i had network connectivity. But after a while, like 30s it worked as it should. I became quite worried there for a while :P
$ cat server.txt
google.com
yahoo.com
redhat.com
$ cat pingalert.sh
#!/bin/bash
# Read the file line by line
cat server.txt | while read line
do
# check if there are no blank lines
if [ ! -z $line ]; then
PINGCOUNT=2
PING=$(ping -c $PINGCOUNT $line | grep received | cut -d ',' -f2 | cut -d ' ' -f2)
if [ $PING -eq 0 ]; then
echo "Something wrong with the server: $line"
# Or do send out mail
else
echo "All good: $line"
fi
fi
done
Output: $ ./pingalert.sh
All good: google.com
All good: yahoo.com
All good: redhat.com
Post a Comment