Shell awk 基础英语案例

该篇博客展示了如何在Linux系统中监控内存、磁盘、CPU使用情况以及网络流量,并通过日志分析进行暴力破解IP地址的检测。内容包括使用`free`命令查看内存,`df`命令查看磁盘,`cpu`命令获取CPU信息,`ifconfig`查看网络流量,以及通过`grep`和`awk`过滤`/var/log/secure`日志来识别暴力破解尝试。
摘要由CSDN通过智能技术生成
  • 监控操系统信息        
[root@zabbix-server ~]# free
              total        used        free      shared  buff/cache   available
Mem:         995896      532348       72036       12052      391512      263968
Swap:       2097148        1288     2095860
[root@zabbix-server ~]# free | awk '{print $7}'

263700

#打印每行最后一列
[root@zabbix-server ~]# free | awk '{print $NF}'
available
263640
2095860
[root@zabbix-server ~]# free | grep Mem
Mem:         995896      532580       71656       12056      391660      263732
[root@zabbix-server ~]# free | awk '/Mem/{print $NF}'
263660
[root@zabbix-server ~]# free | awk '/Mem/{print $NF}'
263668
  • 过滤磁盘信息
[root@zabbix-server ~]# df
文件系统                   1K-块    已用     可用 已用% 挂载点
/dev/mapper/centos-root 17811456 5575636 12235820   32% /
devtmpfs                  480836       0   480836    0% /dev
tmpfs                     497948       0   497948    0% /dev/shm
tmpfs                     497948    8412   489536    2% /run
tmpfs                     497948       0   497948    0% /sys/fs/cgroup
/dev/sda1                1038336  169540   868796   17% /boot
tmpfs                      99592      12    99580    1% /run/user/42
tmpfs                      99592       0    99592    0% /run/user/0
[root@zabbix-server ~]# df | grep "/$"
/dev/mapper/centos-root 17811456 5575636 12235820   32% /
[root@zabbix-server ~]# df | grep "/$" | awk 'print $6'
awk: cmd. line:1: print $6
awk: cmd. line:1: ^ syntax error
[root@zabbix-server ~]# df | grep "/$" | awk '{print $6}'
/
[root@zabbix-server ~]# df | grep "/$" | awk '{print $4}'
12236324
  • 过滤CPU信息
#临时切换英文语言
[root@zabbix-server ~]# LANG=C lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                1
On-line CPU(s) list:   0
Thread(s) per core:    1
Core(s) per socket:    1
Socket(s):             1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 142
Model name:            Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
Stepping:              10
CPU MHz:               1799.999
BogoMIPS:              3599.99
Hypervisor vendor:     VMware
Virtualization type:   full
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              6144K
NUMA node0 CPU(s):     0
Flags:                 fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch ibrs ibpb stibp fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 arat spec_ctrl intel_stibp arch_capabilities
[root@zabbix-server ~]# LANG=C lscpu | grep "Model name" | awk -F: '{print $2}'
            Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
[root@zabbix-server ~]# LANG=C lscpu | grep "^CPU(s)" | awk -F: '{print $2}'
                1
[root@zabbix-server ~]# uptime
 10:35:02 up 42 min,  1 user,  load average: 0.02, 0.04, 0.05
  • 过滤网卡流量
[root@zabbix-server ~]# ifconfig ens32
ens32: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.50  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::6fc0:6e3a:cb75:56d2  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:40:d0:39  txqueuelen 1000  (Ethernet)
        RX packets 3248  bytes 346012 (337.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2080  bytes 246535 (240.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@zabbix-server ~]# ifconfig ens32 | grep "RX p" | awk '{print"进站流量:" $5"字节"}'
进站流量:349360字节
[root@zabbix-server ~]# ifconfig ens32 | grep "TX p" | awk '{print"出站流量:" $5"字节"}'
出站流量:255097字节
[root@zabbix-server ~]# ifconfig ens32 | awk '/RX p/{print"出站流量:" $5"字节"}'
出站流量:384218字节
[root@zabbix-server ~]# ifconfig ens32 | awk '/TX p/{print"出站流量:" $5"字节"}'
出站流量:276949字节

  • 监控暴力破解IP地址
[root@zabbix-server ~]# ssh 192.168.0.50
The authenticity of host '192.168.0.50 (192.168.0.50)' can't be established.
ECDSA key fingerprint is SHA256:9eA1rMtj1s0boZzi69n9W6DZnMRQm2IgEUu0j7A088g.
ECDSA key fingerprint is MD5:c3:25:aa:32:23:1f:a3:76:10:1e:8b:52:22:c9:6b:87.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.0.50' (ECDSA) to the list of known hosts.
root@192.168.0.50's password: 
Permission denied, please try again.
root@192.168.0.50's password: 
Permission denied, please try again.
root@192.168.0.50's password: 
^C
[root@zabbix-server ~]# grep "Failed" /var/log/secure
Dec 12 10:54:18 zabbix-server sshd[9475]: Failed password for root from 192.168.0.50 port 48274 ssh2
Dec 12 10:54:24 zabbix-server sshd[9475]: Failed password for root from 192.168.0.50 port 48274 ssh2
Dec 12 10:54:27 zabbix-server sshd[9475]: Failed password for root from 192.168.0.50 port 48274 ssh2
[root@zabbix-server ~]# grep "Failed" /var/log/secure | awk '{print $11}'
192.168.0.50
192.168.0.50
192.168.0.50

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值