This is a basic Ping Script :
It first pings the 192.168.1.1
then pings the 192.168.2.1
after that it pings the 8.8.8.8
and finally pings the www.google.com address
Why does it pings 1.1 and 2.1 ?
Because my friend wanted to use it in different areas, ( he his not familiar with the shell ) for example at work 1.1 and home 2.1.
Why does it pings 8.8.8.8 and google.com ?
Similar as above 8.8.8.8 is the DNS of google, and google.com is just there, because I like it.
How does it work ? :
Execute the script.sh and it will print out 5 pings to 1.1 and write the result in GREEN / RED and then 5 pings to 2.1 and the result in GREEN / RED
and so one.
The script :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
#!/bin/sh GREEN="\\033[1;32m" NORMAL="\\033[0;39m" RED="\\033[1;31m" clear ####################### 1.1 ################ ping -c 5 192.168.1.1 if [ ! "$?" -eq 0 ]; then echo -e "$RED" "ping 1.1 failed" "$NORMAL" else echo -e "$GREEN" "ping 1.1 passed" "$NORMAL" fi ########################## 2.1 ############## ping -c 5 192.168.2.1 if [ ! "$?" -eq 0 ]; then echo -e "$RED" "ping 2.1 failed" "$NORMAL" else echo -e "$GREEN" "ping 2.1 passed" "$NORMAL" fi ########################## 8.8 ############## ping -c 5 8.8.8.8 if [ ! "$?" -eq 0 ]; then echo-e "$RED" "ping 8.8 failed" "$NORMAL" else echo -e "$GREEN" "ping 8.8 passed" "$NORMAL" fi ########################## GOOGLE ############## ping -c 5 www.google.com if [ ! "$?" -eq 0 ]; then echo -e "$RED" "ping google failed" "$NORMAL" else echo -e "$GREEN" "ping google passed" "$NORMAL" fi |
So have fun 😉
Post a Comment