Linux巡检脚本

做运维的朋友都知道,大家经常要对一些系统做月度维护或者自查,在这个过程中,如果只是小工作量的查询,进入系统直接输入命令即可。但是如果说要查询的系统很多,每个系统中要查询的项目也很多,那么每次都要一次一次地输入命令就很麻烦。所以建议大家在获得管理员的许可的前提下,可以使用脚本。

下面是我写的linux中常见的检查项的脚本,大家可以测试使用,如果有其他的检查项,按照上面的格式添加进去就好。

#!/bin/bash

echo "" > /tmp/shell/xunjian.txt
echo "1  cpu mem " >> /tmp/shell/xunjian.txt
echo "" >> /tmp/shell/xunjian.txt
top -bn 1 | head -n 15  >> /tmp/shell/xunjian.txt

echo "" >> /tmp/shell/xunjian.txt
echo "2  df -h " >> /tmp/shell/xunjian.txt
echo "" >> /tmp/shell/xunjian.txt
df -h >> /tmp/shell/xunjian.txt

echo "" >> /tmp/shell/xunjian.txt
echo "3  hostname  " >> /tmp/shell/xunjian.txt
echo "" >> /tmp/shell/xunjian.txt
hostname  >> /tmp/shell/xunjian.txt

echo "" >> /tmp/shell/xunjian.txt
echo "4  ps aux|more  " >> /tmp/shell/xunjian.txt
echo "" >> /tmp/shell/xunjian.txt
ps aux| more |head -n 10  >> /tmp/shell/xunjian.txt

echo "" >> /tmp/shell/xunjian.txt
echo "5  ifconfig  " >> /tmp/shell/xunjian.txt
echo "" >> /tmp/shell/xunjian.txt
ifconfig  >> /tmp/shell/xunjian.txt

echo "" >> /tmp/shell/xunjian.txt
echo "6  vmstat 1  1  " >> /tmp/shell/xunjian.txt
echo "" >> /tmp/shell/xunjian.txt
vmstat 1  1 >> /tmp/shell/xunjian.txt

echo "" >> /tmp/shell/xunjian.txt
echo "7  date  " >> /tmp/shell/xunjian.txt
echo "" >> /tmp/shell/xunjian.txt
date >> /tmp/shell/xunjian.txt

查询结果如下所示:

1 cpu mem

top - 17:58:35 up 10 min, 2 users, load average: 0.03, 0.14, 0.13

Tasks: 274 total, 1 running, 273 sleeping, 0 stopped, 0 zombie

%Cpu(s): 0.0 us, 7.1 sy, 0.0 ni, 92.9 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st

KiB Mem : 1863076 total, 73052 free, 1156900 used, 633124 buff/cache

KiB Swap: 2097148 total, 2094836 free, 2312 used. 538472 avail Mem

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND

6 root 20 0 0 0 0 S 5.3 0.0 0:03.57 ksoftirqd/0

3217 root 30 10 320188 12700 4860 S 5.3 0.7 0:17.20 urlgrabber+

3316 root 20 0 162020 2180 1516 R 5.3 0.1 0:00.03 top

1 root 20 0 193804 4940 2184 S 0.0 0.3 0:01.60 systemd

2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd

4 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:+

7 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration/0

8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh

2 df -h

Filesystem Size Used Avail Use% Mounted on

devtmpfs 895M 0 895M 0% /dev

tmpfs 910M 0 910M 0% /dev/shm

tmpfs 910M 11M 900M 2% /run

tmpfs 910M 0 910M 0% /sys/fs/cgroup

/dev/sda3 18G 7.1G 11G 41% /

/dev/sda1 297M 161M 137M 54% /boot

tmpfs 182M 4.0K 182M 1% /run/user/42

tmpfs 182M 28K 182M 1% /run/user/1000

/dev/sr0 4.2G 4.2G 0 100% /run/media/red/RHEL-7.7 Server.x86_64

3 hostname

localhost.localdomain

4 ps aux|more

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND

root 1 0.2 0.2 193804 4940 ? Ss 17:47 0:01 /usr/lib/systemd/systemd --switched-root --system --deserialize 22

root 2 0.0 0.0 0 0 ? S 17:47 0:00 [kthreadd]

root 4 0.0 0.0 0 0 ? S< 17:47 0:00 [kworker/0:0H]

root 6 0.5 0.0 0 0 ? S 17:47 0:03 [ksoftirqd/0]

root 7 0.0 0.0 0 0 ? S 17:47 0:00 [migration/0]

root 8 0.0 0.0 0 0 ? S 17:47 0:00 [rcu_bh]

root 9 0.0 0.0 0 0 ? R 17:47 0:00 [rcu_sched]

root 10 0.0 0.0 0 0 ? S< 17:47 0:00 [lru-add-drain]

root 11 0.0 0.0 0 0 ? S 17:47 0:00 [watchdog/0]

5 ifconfig

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500

inet 192.168.188.128 netmask 255.255.255.0 broadcast 192.168.188.255

inet6 fe80::e5ca:68c8:e7fa:5617 prefixlen 64 scopeid 0x20<link>

ether 00:0c:29:f0:d8:bc txqueuelen 1000 (Ethernet)

RX packets 204409 bytes 276329842 (263.5 MiB)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 93187 bytes 5603372 (5.3 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 0 bytes 0 (0.0 B)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 0 bytes 0 (0.0 B)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500

inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255

ether 52:54:00:89:23:f1 txqueuelen 1000 (Ethernet)

RX packets 0 bytes 0 (0.0 B)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 0 bytes 0 (0.0 B)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

6 vmstat 1 1

procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----

r b swpd free buff cache si so bi bo in cs us sy id wa st

0 0 2312 73236 40 633468 0 4 2019 1099 770 1423 3 6 91 0 0

7 date

Sun Sep 3 17:58:35 PDT 2023

8 netstat -nr

Kernel IP routing table

Destination Gateway Genmask Flags MSS Window irtt Iface

0.0.0.0 192.168.188.2 0.0.0.0 UG 0 0 0 ens33

192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0

192.168.188.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33

[root@localhost shell]#

相关推荐
ZhangTao_zata6 分钟前
从python源码到可自动更新软件
linux·开发语言·python
Blood_J7 分钟前
Jenkins配置步骤
运维·servlet·jenkins
IPdodo全球网络40 分钟前
如何解决亚马逊商家IP问题:静态住宅IP的优势与选择指南
大数据·运维·网络
Ray55051 小时前
linux-vlan(1)
linux·运维·网络
五月高高1 小时前
Docker部署Nginx服务器并实现HTTPS自动重定向
服务器·nginx·docker
程序员奇奥1 小时前
CentOS下如何安装Nginx
linux·nginx·centos
葡萄皮Apple1 小时前
[CKS] K8S ServiceAccount Set Up
服务器·容器·kubernetes
დ旧言~1 小时前
【网络】子网掩码
服务器·网络·网络协议·tcp/ip·php·apache
~时光易逝~2 小时前
Linux下sh脚本开启启动
linux·运维·python
华纳云IDC服务商2 小时前
服务器集群不做负载均衡可以吗?
运维·服务器·负载均衡