Shell script Exercise 3

Source: Internet
Author: User

Scan all hosts in the network segment. Online hosts are displayed in green. Offline hosts are displayed in red;

Finally, the numbers of online and offline hosts are displayed respectively;

In order to practice shell, only the for loop is used here, although the efficiency is low, it is not used in the production environment for the purpose of practice.

#!/bin/bash########################################################################## File Name: 005.sh# Author: LookBack# Email: [email protected]# Created Time: Wed 09 Jul 2014 04:06:57 AM CST#########################################################################echo=echofor cmd in echo /bin/echo; do$cmd >/dev/null 2>&1 || continueif ! $cmd -e "" | grep -qE ‘^-e‘; thenecho=$cmdbreakfidoneCSI=$($echo -e "\033[")CEND="${CSI}0m"CDGREEN="${CSI}32m"CRED="${CSI}1;31m"CGREEN="${CSI}1;32m"CYELLOW="${CSI}1;33m"CBLUE="${CSI}1;34m"CMAGENTA="${CSI}1;35m"CCYAN="${CSI}1;36m"CQUESTION="$CMAGENTA"CWARNING="$CRED"CMSG="$CCYAN"declare -i I=0declare -i sum1=0declare -i sum2=0for ((I=0;$I <= 255;I++)); doping -c1 -W1 172.16.250.$I &> /dev/nullcheck=$?if [ "$check" = "0" ]; thenecho "${CGREEN} 172.16.250.$I ${CEND}"let sum1++elseecho "${CWARNING} 172.16.250.$I ${CEND}"let sum2++fidoneecho "${CGREEN} has $sum1 IP online. ${CEND}"echo "${CWARNING} has $sum2 IP offline. ${CEND}"




Shell script Exercise 3

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.