Scripting Basics Exercises

Source: Internet
Author: User

First, script 1, script/root/bin/systeminfo.sh, display the current host system information, including host name, IPV4 address, operating system version, kernel version, CPU model, memory size, hard disk size.    #!/bin/bash#echo  "hostname:       ' hostname '" echo  " ipv4address:    ' ifconfig |grep  ' inet\> '  |sed -nr  ' [email  PROTECTED]*ADDR: (. *) bca.*@\[email protected] "" echo  "system relases:   ' cat /etc/ Centos-release ' "echo " kernel release:   ' uname -r ' "echo " memory size:     ' cat meminfo|grep  ' memtotal "'" echo  "disk size:   ' fdisk -l  | grep  "^disk /dev/s[a-z]" ' "4, script/root/bin/links.sh, shows the IPV4 address and number of connections for each remote host connecting to the host, and sort by the number of connections from large to small    netstat -tn | awk  '/^tcp/{print $4,$1} '  | sort |uniq  -c| sort -n9, write a script/root/bin/hostping.sh, accept the IPV4 address of a host as parameters, test whether it can be connected. If Ping is available, the user is prompted to "This IP address is accessible" and if it is not ping, the user is prompted "The IP address is inaccessible"     #!/bin/bash    #    read -p  "please input a  ipv4 addr:  " addr    ping -W 2 -c 2  $addr   &>/dev/null && echo  "This ipv4addr can be access" | |  echo  "This ipv4addr can not be access" 10, determine whether each partition space of the hard disk and inode utilization is greater than 80, if yes, Email notification root Disk full      #!/bin/bash    #    for  I in  ' df |grep  ' ^/dev/sd " | cut -c 45-46 ';d o       echo  $I          if [  $I  -ge  80 ] ;then           cat /etc/ issue|mail -s  "Warning,please notice you sick"  test            echo  "Successful"          fi    done         for I in  ' df -i|grep  ' ^/dev/sd   | cut -c 41-42 ';d o      echo  $I           if [  $I  -ge 5 ];then            cat /etc/fstab|mail -s  "Warning,please notice you  sick " test           echo " Congratulation "&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;FI&NBSP;&NBSP;&NBSP;&NBSP;DONE11, specified file as parameter To determine if the file is a. sh suffix, and if so, add x permissions     #!/bin/bash    #     read -p  "please input a filename: "  filename    if  [[  $filename  =~ .*\.sh ]];then    chmod a+x  $filename     echo  " Funished "    else    exit     fi12, Determine if the IP entered is legal ip   #!/bin/bash    #    ipaddr= ' ^ (\< ([ 0-9]| [1-9] [0-9]|1[0-9]{2}|2 ([0-4][0-9]|5[0-5])) \>\.) {3}\< ([0-9]|[ 1-9][0-9]|1[0-5][1-9]|2 ([0-4][0-9]|25[0-5]) \>$ '     read -p  ' please  input a ipv4 addr:  " ipv4    if [[  $IPV 4 =~ $ ipaddr ]];then        echo  "A legal IP."     else        echo  "Unlegal ip"   &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;EXIT&NBSP;&NBSP;&NBSP;&NBSP;FI&NBSP;14, enter the starting value A and the last value B, calculate from A + (A+1) ... + ( B-1) The sum of the +b &NBSP;&NBSP;&NBSP;&NBSP;#!/BIN/BASH&NBSP;&NBSP;&NBSP;&NBSP;#&NBSP;&NBSP;&NBSp; sum=0        for i in seq $1 $2;do     let sum+= $I     done    echo  $sum


This article is from the "Mylinux" blog, make sure to keep this source http://luxiangyu.blog.51cto.com/9976123/1836780

Scripting Basics Exercises

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.