shell腳本實現主機信息收集功能

#!/bin/bash
echo "hostname: $(hostname)"
echo "ipaddress: `ifconfig ens224 | grep "inet " | awk '{print $2}'` "
echo "username: `w -i | sed -n '3,$p' |awk '{print $1}'`"
echo "kernel: `uname -r`"

執行結果:

[root@rhel8 home]# sh host_messages.sh 
hostname: rhel8.0-clone
ipaddress: 172.25.254.11 
username: root
kernel: 4.18.0-80.el8.x86_64
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章