Have finished the shell, write a little script to show you

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.