In Linux has been learning for one months, today to write a small script, wrote three different, although simple, but you can see, I wrote the script is ping3 times to see if the host is alive!
The first one is ~ ~ for~~ loop because I knocked it over at the terminal, so I copied it.
For IP in
cat ip.txt
Do
For count in {1..3}
Do
PING-C1-W1 $ip &>/dev/null
If [$?-eq 0];then
echo "$ip is OK"
else echo "$ip is shibaid:$count" #shibaide[$count]=$ip fi done if [ ${#shibaide[$count]} -eq 5 ];then echo "${shibaide[$count]} ping不通过"
Fi
Done
This is relatively simple, the script this kind of thing, as long as they feel good to be able to see everyone's way
Here is the second set of functions
#!/bin/bash
############# #是否可以ping通 #############
Ok () {
PING-C1 $ip &>/dev/null
If [$?-eq 0];then
echo "$ip is OK"
Continue
Fi
}
While read IP
Do
Ok
Ok
Ok
echo "$ip is Huai de"
Done <ip.txt
~ This is set up outside the function and then in the set while loop this is more similar than the previous, we can learn from the reference thank you * * * *
Have finished the shell, write a little script to show you