2017 the latest enterprise face Test Shell (ii)

Source: Internet
Author: User

2017 the latest enterprise face Test Shell (ii)



Exercise 1:
write a shell script that lists the IP of the 192.169.5.0/24 network segment online. (Locate the active IP)

Requirements are as follows:

1. The online IP and the online IP are placed in two files respectively to facilitate later inspection;

2. Do not affect the operation of the current terminal;

3. After the script has finished running, give the message that the script has finished running.

The script reads as follows:

Method One:

#!/bin/bash

[-f/etc/init.d/functions] &&. /etc/init.d/functions| | Exit1

# Verify that the system function file exists and call the system function if it exists, otherwise quit!

Ips= "192.169.5."

For I in $ (seq 254)

Do

Ping-c 2 $ips $i >/dev/null 2>/dev/null

If ["$?" = = "0"]

Then

echo "Echo $ips $i is online" >>/root/ip_online.txt

Else

echo "Echo $ips $i is not online" >>/root/ip_noline.txt

Fi

Done

If ["$ips $i"! = "192.169.5.255"];then

Action "shell script execution is complete! "/bin/true

Fi

Method Two:

#!/bin/bash

[-f/etc/init.d/functions] &&. /etc/init.d/functions| | Exit1

# Verify that the system function file exists and call the system function if it exists, otherwise quit!

For IP in $ (cat/root/ip.txt)

Do

Ping-c 2 $ip >/dev/null 2>/dev/null

If ["$?" = = "0"]

Then

echo "Echo $ip is online" >>/root/ip_online.txt

Else

echo "Echo $ip is not online" >>/root/ip_noline.txt

Fi

Done

If ["$ip"! = "192.169.5.255"];then

Action "shell script execution is complete! "/bin/true

Fi

Description

(1) If the script name ip_online.sh, execute the script without affecting the use of the current terminal, using the SH ip_online.sh & command.

(2) It is not recommended to use method two because editing a/root/ip.txt file is a waste of time.

This article is from the "Hand of the Paladin Control" blog, please make sure to keep this source http://wutengfei.blog.51cto.com/10942117/1961226

2017 the latest enterprise face Test Shell (ii)

Related Article

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.