Linux 下 查看系统信息 的方法 脚本

能够较为准确的计算出已安装硬盘容量.
不提供比较鸡肋的延迟和测速功能.

  • 使用:
bash -c "$(wget –no-check-certificate -qO- 'https://moeclub.org/attachment/LinuxShell/bench.sh')"
  • 脚本代码:
#!/bin/bash
 
get_opsy() {
    [ -f /etc/redhat-release ] && awk '{print ($1,$3~/^[0-9]/?$3:$4)}' /etc/redhat-release && return
    [ -f /etc/os-release ] && awk -F'[= "]' '/PRETTY_NAME/{print $3,$4,$5}' /etc/os-release && return
    [ -f /etc/lsb-release ] && awk -F'[="]+' '/DESCRIPTION/{print $2}' /etc/lsb-release && return
}
 
next() {
    printf "%-70s\n" "-" | sed 's/\s/-/g'
}
 
io_test() {
    (LANG=en_US dd if=/dev/zero of=test_$$ bs=64k count=16k conv=fdatasync) 2>&1 | awk -F, '{io=$NF} END { print io}' | sed 's/^[ \t]*//;s/[ \t]*$//'
    rm -rf test_*;
}
 
read_Free() {
    Free="0"
    for addFree in `df |awk -v c=$1 '/^\/dev/{print $c}'`
      do 
        [ -n "$(echo "$addFree" |grep '[^0-9.]')" ] && echo "$addFree" && break;  
        Free=$( awk 'BEGIN{print '$Free' + '$addFree'}' )
      done
    [ $Free != '0' ] && {
    for UNIT in `echo 'M G T P'`
      do
        Free=$( awk 'BEGIN{print '$Free' / '1024'}' )
        [[ "$(echo -n "$Free" |cut -d'.' -f1)" -lt '1024' ]] && break;
        [ $UNIT == 'P' ] && break;
      done
    echo "$Free$UNIT"
    }
}
 
    cname=$( awk -F: '/model name/ {name=$2} END {print name}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//' )
    cores=$( awk -F: '/model name/ {core++} END {print core}' /proc/cpuinfo )
    freq=$( awk -F: '/cpu MHz/ {freq=$2} END {print freq}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//' )
    tram=$( free -m | awk '/Mem/ {print $2}' )
    swap=$( free -m | awk '/Swap/ {print $2}' )
    disk=$( read_Free '2' )
    fred=$( read_Free '4' )
    usdp=$( read_Free '5' )
    up=$( awk '{a=$1/86400;b=($1%86400)/3600;c=($1%3600)/60;d=$1%60} {printf("%d days, %d:%d:%d\n",a,b,c,d)}' /proc/uptime )
    load=$( w | head -1 | awk -F'load average:' '{print $2}' | sed 's/^[ \t]*//;s/[ \t]*$//' )
    opsy=$( get_opsy )
    arch=$( uname -m )
    lbit=$( getconf LONG_BIT )
    kern=$( uname -r )
 
    clear
    next
    echo -e "\t\t\tInformation View"
    next
    echo "CPU model            : $cname"
    echo "Number of cores      : $cores"
    echo "CPU frequency        : $freq MHz"
    echo "Total RAM/SWAP       : $tram MB/$swap MB"
    echo "Disk capactiy        : $fred/$disk ($usdp)"
    echo "System uptime        : $up"
    echo "Load average         : $load"
    echo "OS                   : $opsy"
    echo "Arch                 : $arch ($lbit Bit)"
    echo "Kernel               : $kern"
next
 
    echo -ne "I/O speed   :"
    io1=$( io_test )
    echo -ne " $io1"
    io2=$( io_test )
    echo -ne "    $io2"
    io3=$( io_test )
    echo -ne "    $io3\n"
    ioraw1=$( echo $io1 | awk 'NR==1 {print $1}' )
    [ "`echo $io1 | awk 'NR==1 {print $2}'`" == "GB/s" ] && ioraw1=$( awk 'BEGIN{print '$ioraw1' * 1024}' )
    ioraw2=$( echo $io2 | awk 'NR==1 {print $1}' )
    [ "`echo $io2 | awk 'NR==1 {print $2}'`" == "GB/s" ] && ioraw2=$( awk 'BEGIN{print '$ioraw2' * 1024}' )
    ioraw3=$( echo $io3 | awk 'NR==1 {print $1}' )
    [ "`echo $io3 | awk 'NR==1 {print $2}'`" == "GB/s" ] && ioraw3=$( awk 'BEGIN{print '$ioraw3' * 1024}' )
    ioall=$( awk 'BEGIN{print '$ioraw1' + '$ioraw2' + '$ioraw3'}' )
    ioavg=$( awk 'BEGIN{print '$ioall'/3}' )
    echo "I/O Average : $ioavg MB/s"
next
    echo
    exit 0;

 

来源: 腾讯云Qcloud评测
日期: 2017-8-24
作者: 腾讯云/服务器VPS推荐评测/Vultr
阅读数: 60
链接到文章: https://ixvps.com/43427.html

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注