创意叙事项目工程化实践:从概念到交付的全链路管理
2026/9/4 16:08:48
脚本放到 /etc/profile.d/ 目录下即可(Centos5,6,7,Kylin,UOS(a))
#!/bin/bash #================================================================== # FileName : system_info.sh # CreateTime : root 2024-06-04 10:10:44 # ModifyTime : root 2026-08-18 10:10:44 # Sversion : v3.2 #================================================================== color_setting(){ HC='\033[37;1m' #高亮 RC='\033[31;1m' #红色 error GC='\033[32;1m' #绿色 success YC='\033[33;1m' #黄色 warning BC='\033[34;1m' #蓝色 output DC='\033[35;1m' #粉色 detail AC='\033[36;1m' #天蓝 info EC='\033[0m' #黑白 } get_info(){ if [[ -e /etc/system-release ]];then Verfile='/etc/system-release' elif [[ -e /etc/redhat-release ]];then Verfile='/etc/redhat-release' fi #[系统版本] os_version=$(cat ${Verfile}|grep -E -o '[0-9]{1,3}'|head -n 1) if [[ ${os_version} -eq 5 ]];then export LANG=en_US.UTF-8 fi #[信息] HN=$HOSTNAME PRODUCT=$(echo $(/usr/sbin/dmidecode |grep -E -A2 'System Information'|grep -E Product|awk -F: '{print $NF}')) SN=$(echo $(/usr/sbin/dmidecode |grep -E -A4 'System Information'|grep -E 'Serial Number'|awk -F: '{print $NF}')|tr -d ' ') DT=$(date +"%Y-%m-%d,%H:%M:%S") VER=$(cat ${Verfile}|grep -v '^#')" "${GC}$(uname -p)${EC} HE=$(uname -sr) 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|awk '{if($1>=90) {print "'"${RC}"'"$1"'"${EC}"'",$2,$3} else {print "'"${GC}"'"$1"'"${EC}"'",$2,$3}}') IPadd=$(if command -v ip >/dev/null 2>&1; then ip -o -4 addr show |awk '{print $2, $4}'|grep -E -v 'lo|virbr0'|while read -r interface ip; do mac=$(ip link show "$interface" | awk '/ether/ {print $2}'); echo "$interface: $ip MAC: $mac"|awk -F '[ ]' '{printf "%23s%-30s%8s%-1s\n",$1" ","'${AC}'"$2"'${EC}' ",$3" ","'${AC}'"$4"'${EC}' "}';done;fi|awk -F ' ' '{if (NR == 1) {printf " IPv4 : %s %-45s %-1s %-15s\n", $1,$2,$3,$4} else {printf " : %s %-45s %-1s %-15s\n",$1,$2,$3,$4}}' && if command -v ip >/dev/null 2>&1; then ip -o -6 addr show |awk '{print $2, $4}'|grep -E -v 'lo|virbr0'|while read -r interface ip; do mac=$(ip link show "$interface" | awk '/ether/ {print $2}'); echo "$interface: $ip MAC: $mac"|awk -F '[ ]' '{printf "%23s%-30s%8s%-1s\n",$1" ","'${AC}'"$2"'${EC}' ",$3" ","'${AC}'"$4"'${EC}' "}';done;fi|awk -F ' ' '{if (NR == 1) {printf " IpV6 : %s %-45s %-1s %-15s\n", $1,$2,$3,$4} else {printf " : %s %-45s %-1s %-15s\n",$1,$2,$3,$4}}') #[cpu部分] s=$(grep 'physical id' /proc/cpuinfo|sort -u|wc -l);c=$(awk '/core id/{print $NF}' /proc/cpuinfo|sort -u|wc -l);l=$(grep -c '^processor' /proc/cpuinfo);t=$(( c==0 ? 1 : l/c )); cpu_info="$(awk -F: '/model name/ {name=$2} END {print name}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//') | Socket:${s} PhysicalCores:${c} LogicNum:${l} ThreadsPerCore:${t}" #[内存swap] mem_used=$(free -m | grep Mem | awk '{print$3}') mem_total=$(free -m | grep Mem | awk '{print$2}') swap_used=$(free -m | awk '/Swap/ {print $3}') swap_total=$(free -m | awk '/Swap/ {print $2}') M_info=$(free|grep -v buff|awk 'NR==1{printf "%.0f\n",$3/$2*100}'|awk '{if($1>=80) {print "'${mem_used}' MB / '${mem_total}' MB ('"${RC}"'"$1"'"${EC}"'% Used)"} else {print "'${mem_used}' MB / '${mem_total}' MB ('"${GC}"'"$1"'"${EC}"'% Used)"}}') S_info=$(free -m|grep Swap|grep -v buff|awk '{if($2>0) {printf "%.0f\n",$3/$2*100} else {printf "%.0f\n",0}}'|awk '{if($1>=80) {print "'${swap_used}' MB / '${swap_total}' MB ('"${RC}"'"$1"'"${EC}"'% Used)"} else {print "'${swap_used}' MB / '${swap_total}' MB ('"${GC}"'"$1"'"${EC}"'% Used)"} }') #[Cpu负载信息] load1=$(uptime |awk '{print $(NF-2),$(NF-1),$(NF)}'|awk -F , '{print $(NF-2),$(NF-1),$(NF)}'|awk '{if($1>=80) {print "'"${RC}"'"$1"'"${EC}"'"} else {print "'"${GC}"'"$1"'"${EC}"'"}}')"(1m) " load2=$(uptime |awk '{print $(NF-2),$(NF-1),$(NF)}'|awk -F , '{print $(NF-2),$(NF-1),$(NF)}'|awk '{if($2>=80) {print "'"${RC}"'"$2"'"${EC}"'"} else {print "'"${GC}"'"$2"'"${EC}"'"}}')"(5m) " load3=$(uptime |awk '{print $(NF-2),$(NF-1),$(NF)}'|awk -F , '{print $(NF-2),$(NF-1),$(NF)}'|awk '{if($3>=80) {print "'"${RC}"'"$3"'"${EC}"'"} else {print "'"${GC}"'"$3"'"${EC}"'"}}')"(15m)" #[用户进程信息] user_list=$(grep "bash$" /etc/passwd|awk -F [:] '{print $1}') for u in $user_list;do Pro_detail=$(ps aux | grep $u|grep -v 'grep' | wc -l)"($u)" Pro_user+=$Pro_detail" " done Ulo=$(who|wc -l) #[登录信息] if [[ $os_version -eq 5 ]];then LastB=$(who -b|awk '{print $(NF-2),$(NF-1),$(NF)}') else LastB=$(who -b|awk '{print $(NF-1),$(NF)}') fi LastL=$(last -n 1 | head -n 1|awk '{print $1,$3,"at",$4,$5,$6,$7}') } get_filesystem(){ FS=$(while read line; do awk '{if($6>=80) {printf "%-s%-40s%-8s%-10s%8s%8s%27s\n"," Mounted: ",$1,$2,$3,$4,$5," ('"${RC}"'"$6"'"${EC}"'% Used)"} else {printf "%-s%-40s%-8s%-10s%8s%8s%27s\n"," Mounted: ",$1,$2,$3,$4,$5," ('"${GC}"'"$6"'"${EC}"'% Used)"}}' <<< ${line} percent=$(echo "${line}"|awk '{print $6}'); PROGRESS_BAR_WIDTH=93 for i in ${percent}; do if [[ ${percent} -ge 80 ]];then echo -ne "$i%" | awk -v width=$PROGRESS_BAR_WIDTH '{ done = int($1/100*width); undone = width - done; printf(" ["); for(i=0; i<done; i++) {printf("'"${RC}"'='"${EC}"'");} for(i=0; i<undone; i++) {printf(" ");} printf("]"); printf("\r"); }' else echo -ne "$i%" | awk -v width=$PROGRESS_BAR_WIDTH '{ done = int($1/100*width); undone = width - done; printf(" ["); for(i=0; i<done; i++) {printf("'"${GC}"'='"${EC}"'");} for(i=0; i<undone; i++) {printf(" ");} printf("]"); printf("\r"); }' fi done echo done <<< "$(df -ThP|grep -E -v 'tmpfs|Filesystem|挂载点'|grep -E -v '/boot|^10'|awk '{gsub("%"," ");print $1,$2,$7,$3,$4,$6}'|sort -k1,3)") } output(){ clear echo -e "${HC}[System Info] Hostname : ${YC}$HOSTNAME${EC} Current Time : ${DT} OS_Version : ${VER} Kernel : ${HE} Machine_Type : ${PRODUCT} Machine_SN : ${SN} Uptime : ${UP} ${IPadd} Cpu : ${cpu_info} Memory : ${M_info} SWAP : ${S_info} Load avg : ${load1} ${load2} ${load3} Processes : ${Pro_user} Users Logged on : ${Ulo} Last Boot : ${LastB} Last Login : ${LastL} [Filesystem Info] Mounted: Filesystem Type Mountpoint Total Used (Used%) ${FS} ${EC}" } main(){ if [[ $EUID -eq 0 ]];then color_setting get_info get_filesystem output fi } main "$@"