--- tags: BASH --- # BASH_機器規格(選單) ```bash= #!/bin/bash while : do echo -e '機器規格選單 1.CPU 2.Hard Disk 3.Memory 4.主機名稱 5.帳號列表 6.離開' read -p "請輸入 1-6 選項?" number case $number in 1) #!/bin/bash cat /proc/cpuinfo | grep 'model name' | head -n 1 | cut -d ':' -f2 read -p "請按 Enter 鍵返回" ;; 2) #!/bin/bash df -h | grep '/dev/sda2' | fmt -u | cut -d ' ' -f2 read -p "請按 Enter 鍵返回" ;; 3) #!/bin/bash free -mh | grep 'Mem:' | tr -s ' ' | cut -d ' ' -f2 read -p "請按 Enter 鍵返回" ;; 4) #!/bin/bash cat /etc/hostname read -p "請按 Enter 鍵返回" ;; 5) #!/bin/bash cat /etc/passwd | tail -n -3 | cut -d ':' -f1 read -p "請按 Enter 鍵返回" ;; 6) break ;; *) echo "請選 1,2,3,4 ?" esac done echo "謝謝" ``` --- # 主機名 及 硬體架構等..名稱 ```bash= #!/bin/bash [ "$USER" != "root" ] && echo "no root to run" && exit 1 echo -n "主機名稱:" cat /etc/hostname echo -n "IP:" ifconfig|grep "inet "|head -n 1|tr -s ' '|cut -d ' ' -f3 echo -n "netmask:" ifconfig|grep "inet "|head -n 1|tr -s ' '|cut -d ' ' -f5 echo -n "gateway:" route -n|grep "0.0.0.0"|head -n 1|fmt -u|cut -d " " -f2 echo -n "DNS:" cat /etc/resolv.conf|grep nameserver|cut -d " " -f2 echo -n "主機的硬體架構名稱:" uname -m echo -n "記憶體容量:" free -mh|grep "Mem:"|fmt -u|cut -d " " -f2 echo -n "硬碟容量:" df -h|grep "/dev/sda2"|fmt -u|cut -d " " -f2 echo -n "CPU:" cat /proc/cpuinfo|grep "model name"|head -n 1|tr -s ' '|cut -d ":" -f2 echo -n "內核發行版本:" uname -r echo -n "Ubuntu 版本:" cat /etc/issue.net ``` --- # h1 ```bash= #!/bin/bash [ $USER != "root" ] && echo "need root to run" && exit while : do echo -e '選單 1.系統資訊 2.檢查可用IP 3.離開' read -p "請輸入選項1-3:" num case $num in 1) ./sys.sh ;; 2) ./testforseq02 ;; 3) break ;; *) echo "請選1-3" esac done echo "Bye" ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up