shell script (System Toolbox V2)

                                    shell scripts System Toolbox V2

After two months of study, the most recent summary of some of the things shell script, the system toolbox should be part of the end for the time being out of shell scripts, July-August to re-write anything over operation and maintenance, refueling ~

#!/bin/bash
#################
# System Toolbox v2
# June 10, 2019 14:44:36
#################
# 1, interpretation system is redhat, or other
# 2, the interpretation of whether the user is root
# 3, to determine whether the tool has been installed
# 4 print kit

# Determination system, the system according to the installation command assigned different variable ##############################
sys1=`cat /etc/redhat-release | cut -d " " -f1`
sys2=`cat /etc/issue | cut -d " " -f1`
if [[ $sys1 == CentOS || $sys1 == RedHat ]];then
        R_M=yum
elif [  $sys2 == Debian ];then
        R_M=apt-get
else
        echo "Unrecorded System Name......"
        exit
be
####################### Analyzing System ######################### #################



#################################################################
# Determine the user login is not root, you can use the system variable $ LOGNAME
user=`echo $LOGNAME`
if [ $user != "root" ];then
        echo 'please use root user action.....'
        exit
be
########################### judgment login #################### #####


#################################################################
# Determine whether vmstat, iotp tool, no installation
which vmstat &>/dev/null
if [ $? -ne 0 ];then
        $R_M install vmstat -y
be
which iotop &>/dev/null
if [ $? -ne 0 ];then
        $R_M install iotop -y
be
###############################################################


####################################################################
#cpu_load function, the following case statement calls
cpu_load() {
cpu_sy = `vmstat | awk '{if (NR == 3) print $ 14}' `
cpu_us=`vmstat | awk '{ if(NR==3) print $15}'`
cpu_wa=`vmstat | awk '{ if(NR==3) print $16}'`
        for i in `seq 3`
        do
        echo -e "\e[1;35m  Real-time value $i \e[1;0m"
        echo -e "\e[1;34m  system time $cpu_sy \e[1;0m"
        echo -e "\e[1;34m  cpu free ${cpu_us}% \e[1;0m"
        echo -e "\e[1;34m  io wait $cpu_wa \e[1;0m"
                sleep 1
        done
}
#########################################################################
#disk_load function, the following case statement calls
disk_load() {
        util=`iostat -x -k | awk 'BEGIN{ OFS=": "} /^[v|s]/ { print $1,$NF"%"}'`
        readi=`iostat -x -k | awk 'BEGIN{ OFS=": "} /^[s|v]/ { print $1,$4"kb/s" }'`
        write=`iostat -x -k | awk 'BEGIN{ OFS=": "} /^[s|v]/ { print $1,$5"kb/s" }'`
        echo "util is:\n $util"
        echo "read is:\n$readi"
        echo "write is:\n$write"
}
######################################################################


# This is the actual system variables PS3, you can define, for aesthetic here, otherwise the output format is # ?, Comparative ugly
PS3="please enter your choice(1~9): "
#while cycle is repeated to print message. The message here is not to use printf, did not use EOF, but select. This format like for i in ... do done, but the format can not be customized,
It's only in accordance with 1,2,3 ..... interspersed with matching case statement select statement options.
while :
do
select info in cpu_load disk_load disk_use disk_inode mem_use tcp_status cpu_top10 mem_top10 quit
do
        clear
        case  $info in
        cpu_load)
                cpu_load
        break
;;
        disk_load)
                    disk_load
        break
;;
        disk_use)
                df -h
        break
;;
        disk_inode)
                echo "disk inode"
        break
;;
        mem_use)
                free -m
        break
;;
        tcp_status)
                ss -an |grep ESTAB | grep '\<22\>'
        break
;;
        cpu_top10)
                ps aux|head -1;ps aux|grep -v PID|sort -rn -k +3| head -10
        break
;;
        mem_top10)
                ps aux|head -1;ps aux|grep -v PID|sort -rn -k +4|head -10
        break
;;
        quit)
                exit
;;
        *)
                echo "error,please enter 1-9"
        break
        esac
done
done


Guess you like

Origin blog.51cto.com/13760226/2414545