[内容] Linux 网卡 IP 地址的显示

方法一:ip 命令

# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:1c:42:c9:3c:81 brd ff:ff:ff:ff:ff:ff
    inet 10.10.10.129/24 brd 10.10.10.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fdb2:2c26:f4e4:0:55da:1265:541f:8007/64 scope global temporary dynamic 
       valid_lft 563315sec preferred_lft 44695sec
    inet6 fdb2:2c26:f4e4:0:21c:42ff:fec9:3c81/64 scope global dynamic mngtmpaddr 
       valid_lft 2591846sec preferred_lft 604646sec
    inet6 fe80::21c:42ff:fec9:3c81/64 scope link 
       valid_lft forever preferred_lft forever

或者:

# ip a s
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:1c:42:c9:3c:81 brd ff:ff:ff:ff:ff:ff
    inet 10.10.10.129/24 brd 10.10.10.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fdb2:2c26:f4e4:0:55da:1265:541f:8007/64 scope global temporary dynamic 
       valid_lft 563315sec preferred_lft 44695sec
    inet6 fdb2:2c26:f4e4:0:21c:42ff:fec9:3c81/64 scope global dynamic mngtmpaddr 
       valid_lft 2591846sec preferred_lft 604646sec
    inet6 fe80::21c:42ff:fec9:3c81/64 scope link 
       valid_lft forever preferred_lft forever

或者:

# ip address show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:1c:42:c9:3c:81 brd ff:ff:ff:ff:ff:ff
    inet 10.10.10.129/24 brd 10.10.10.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fdb2:2c26:f4e4:0:55da:1265:541f:8007/64 scope global temporary dynamic 
       valid_lft 563315sec preferred_lft 44695sec
    inet6 fdb2:2c26:f4e4:0:21c:42ff:fec9:3c81/64 scope global dynamic mngtmpaddr 
       valid_lft 2591846sec preferred_lft 604646sec
    inet6 fe80::21c:42ff:fec9:3c81/64 scope link 
       valid_lft forever preferred_lft forever

方法二:ifconfig 命令

# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.10.10.129  netmask 255.255.255.0  broadcast 10.10.10.255
        inet6 fdb2:2c26:f4e4:0:21c:42ff:fec9:3c81  prefixlen 64  scopeid 0x0<global>
        inet6 fe80::21c:42ff:fec9:3c81  prefixlen 64  scopeid 0x20<link>
        inet6 fdb2:2c26:f4e4:0:55da:1265:541f:8007  prefixlen 64  scopeid 0x0<global>
        ether 00:1c:42:c9:3c:81  txqueuelen 1000  (Ethernet)
        RX packets 698666  bytes 485434755 (462.9 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 372557  bytes 699406543 (667.0 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 73792  bytes 394285172 (376.0 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 73792  bytes 394285172 (376.0 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

方法三:iwconfig 命令

# iwconfig 
lo        no wireless extensions.

eth0      no wireless extensions.

[工具] Shell 显示系统常用信息

介绍

基本信息

作者:朱明宇
名称:显示系统常用信息
作用:显示系统常用信息

使用方法

1. 在此脚本的分割线内写入相应的内容
2. 给此脚本添加执行权限
3. 执行此脚本

脚本分割线里的变量

1. times=5 #显示系统常用信息的次数
2. sleeptime=0.3 #大部分行与行之间显示的间隔时间

注意

1. 需要安装 sysstat 软件
2. 执行此脚本的用户能够使用 sudo ip a s 命令
3. 执行此脚本的用户能够使用 sudo ss -ntulap 命令
4. 搭建了 KVM 虚拟化平台后执行此脚本的用户能够使用 sudo virsh list 命令后才能实现

脚本

#!/bin/bash

####################### Separator ########################
times=5
sleeptime=0.3
####################### Separator ########################

nowtime=1

while (( nowtime <= times))
do
        echo -e "Start Monitoring: \c"
	for i in {1..94}
	do
	        echo -e "#\c"
		sleep 0.01
        done
	echo

	sleep $sleeptime
        host=`hostname`
        echo -e "Name:\t\t\t\t\t\t\t \033[1m$host\033[0m"

        ip=`sudo ip a s | awk '/[1-2]?[0-9]{0,2}\.[1-2]?[0-9]{0,2}/&&!/127.0.0.1/{print $2}' | awk -F/ '{print $1}'`
	for iip in $(echo $ip)
        do
		sleep $sleeptime
                echo -e "IP Address:\t\t\t\t\t\t \033[1m$iip\033[0m"
        done

        sleep $sleeptime

        cpu=`top -bn 1 | awk -F',' '/^%Cpu/{print $4 }' | awk '{print $1}' | awk '{print 100-$1}'`
        echo -e "CPU Usage (Total):\t\t\t\t\t \033[1m$cpu%\033[0m"

        sleep $sleeptime

        mem=`free | grep Mem | awk '{print $3/$2 * 100.0}' | egrep -o "[1]?[0-9]{0,2}\.[0-9]"`
        echo -e "Memory Usage (Total):\t\t\t\t\t \033[1m$mem%\033[0m"

	directory=`df -h | grep -v run | grep -v boot | awk '$1~/\/dev/{print $6}'`
        for idirectory in `echo $directory`
        do
                sleep $sleeptime
                directoryusage=`df -h | grep -v run | grep -v boot | awk '$1~/\/dev/{print}' | grep $idirectory$ | awk '{print $5}'`
		if [ $idirectory == / -o $idirectory == /sda -o $idirectory == /sdb  ];then
                        echo -e "Directory Usage ($idirectory):\t\t\t\t\t \033[1m$directoryusage\033[0m"
	        else
                        echo -e "Directory Usage ($idirectory):\t\t\t\t \033[1m$directoryusage\033[0m"
		fi
        done

	sudo -l | grep 'virsh list' &> /dev/null
        if [ $? -eq 0 ];then
	        sleep $sleeptime
	        virtual=`sudo virsh list | egrep [0-9] | wc -l`
	        echo -e "Number of Virtual Machines (Total):\t\t\t \033[1m$virtual\033[0m"
        fi

        sleep $sleeptime

        user=`who | wc -l`
        echo -e "Number of User Logins (Total):\t\t\t\t \033[1m$user\033[0m"

        soft=`rpm -qa | wc -l`
        echo -e "Number of Softwares (Total):\t\t\t\t \033[1m$soft\033[0m"

        sleep $sleeptime

        port=`sudo ss -ntulap | wc -l`
        echo -e "Number of Open Ports (Total):\t\t\t\t \033[1m$port\033[0m"

        which sar &> /dev/null
        if [ $? -eq 0 ];then
                networkcard=`ifconfig | awk -F: '/flags/&&!/lo/{print $1}'`
                for inetworkcard in `echo $networkcard`
                do
                        networkread="`sar -n DEV 1 1 | grep $inetworkcard | awk '/[0-9][0-9]:[0-9][0-9]/{print $3/1000}'` m/s"
                        networkwrite="`sar -n DEV 1 1 | grep $inetworkcard | awk '/[0-9][0-9]:[0-9][0-9]/{print $4/1000}'` m/s"
			echo $inetworkcard | grep eth &> /dev/null
			if [ $?  -ne 0 ];then
	                echo -e "Network Card IO ($inetworkcard):\t\t\t\t \033[1m$networkread\033[0m (Read)\t\033[1m$networkwrite\033[0m (Write)"
		        else
	                echo -e "Network Card IO ($inetworkcard):\t\t\t\t\t \033[1m$networkread\033[0m (Read)\t\033[1m$networkwrite\033[0m (Write)"
			fi
                done
        fi

        which iostat &> /dev/null
        if [ $? -eq 0 ];then
	        disk=`iostat -d -k 1 1 | awk '!/^$/&&!/Device/&&!/Linux/{print $1}'`
                for idisk in `echo $disk`
	        do
			sleep $sleeptime
		        diskread="`iostat -d -k 1 1 | grep $idisk |  awk '{print $3/1000}'` m/s"
		        diskwrite="`iostat -d -k 1 1 | grep $idisk |  awk '{print $4/1000}'` m/s"
			echo $idisk | grep 'nvme' &> /dev/null
			if [ $? -eq 0 ];then
		                echo -e "Disk IO (/dev/$idisk):\t\t\t\t\t \033[1m$diskread\033[0m (Read)\t\033[1m$diskwrite\033[0m (Write)"
		        else
		                echo -e "Disk IO (/dev/$idisk):\t\t\t\t\t \033[1m$diskread\033[0m (Read)\t\033[1m$diskwrite\033[0m (Write)"
			fi
	        done

        fi

        echo -e "Complete Monitoring: \c"
        for i in {1..91}
        do
                echo -e "#\c"
                sleep 0.01
        done
        echo
        sleep $sleeptime

        let nowtime++
done

        echo -e "Terminal Monitoring: \c"
        for i in {1..91}
        do
                echo -e "#\c"
                sleep 0.01
        done

exit

[命令] Linux 命令 lsscsi (查看硬盘类型,例:SSD、HD、SATA、FC ……)

内容一:lsscsi 命令的格式

# lsscsi <option>

内容二:lsscsi 命令的选项

1) -c 以硬盘全称的形式显示硬盘默认信息
2) -d 显示硬盘主设备号和次设备号
3) -g 显示硬盘对应的 sg 设备
4) -H 显示硬盘的控制器列表
5) -i 显示硬盘的 udev 信息
6) -l 显示硬盘状态
7) -ll 显示硬盘状态,比 -l 选项能显示更多信息
8) -lll 或者 -L 显示硬盘状态,比 -ll 选项能显示更多信息
9) -p 显示硬盘的 DIF DIX 保护类型
10) -P 显示硬盘有效的保护类型
11) -s 显示硬盘容量
12) -v 显示硬盘设备所在目录
13) -w 显示硬盘的 WWN 信息
14) -x 以 16 进制显示硬盘的 lun 号

[内容] Linux 常用日志 (openSUSE & SUSE 版)

1) /var/log/boot.msg,包含系统启动时显示在屏幕上的信息
(补充:当进入系统时,可以同时按下 “ctrl” 键和 “alt” 键和 “f10” 键切换到显示日志的界面,之后可以再通过 KVM 显示系统启动时显示在屏幕上的信息。)
2) /var/log/boot.omsg,包含上一次系统启动时显示在屏幕上的信息
3) /var/log/messages,包含几乎所有日志
4) /var/log/warn,包含 WARNING 也就是级别 4 以上的所有日志
5) /var/log/wtmp,包含和系统登录和重启的所有日志
(补充:可以通过 last 命令读取)
6) /var/log/YaST2/y2log,包含 YaST 的所有日志
7) /var/log/xinetd.log,包含 xinetd 服务的所有日志
8) /var/log/dump/,包含 Kdump 工具在系统宕机时收集的所有故障信息
9) /var/log/atop,包含 Atop 工具收集的系统资源 (CPU、内存、系统进程、IO) 的所有使用信息

[内容] Linux CPU 温度的显示 (直接显示)

内容一:显示 CPU 的瞬时温度

# cat /sys/class/thermal/thermal_zone0/temp


补充:
1) 这里以显示第 1 个 CPU 的瞬时温度为例
2) 将显示的数值除以 1000 就是以摄氏为单位的温度
3) 如果显示第 2 个 CPU 的瞬时温度则将 thermal_zone0 换成 thermal_zone1

内容二:显示 CPU 的瞬时温度,并对数值进行处理

# echo "CPU Temperature: $[$(cat /sys/class/thermal/thermal_zone0/temp)/1000]"


补充:
1) 这里以显示第 1 个 CPU 的瞬时温度为例
2) 如果显示第 2 个 CPU 的瞬时温度则将 thermal_zone0 换成 thermal_zone1