Linux shell脚本查看系统版本、CPU等脚本汇总

一、编写系统脚本显示当前主机名、CPU、IPv4、内存,磁盘

 1 #!/bin/bash
  2 #
  3 #*********************************
  4 #Auther:      xi
  5 #Date:        2024-12-26
  6 #FileName:    syainfo.sh
  7 #URL:         http://www.xxx.com
  8 #Description: test
  9 #Copyright(C):2024 All right
 10 #**********************************
 11  echo "Hostname":`hostname`
 12  echo "IPv4 address IPv4地址:" `ifconfig ens160 | grep -Eo '([0-9]{1,3}.){3}[0-9]{1,3}'| head -n1`
 13  echo "OS version版本:" `cat /etc/redhat-release`
 14  echo "KernelVersion内核版本:" `uname -r`
 15  echo "CPU型号:" `lscpu | grep "^Model name" | tr -s ""| cut -d: -f2`
 16  echo "Memery内存大小:" `cat /proc/meminfo | grep MemTotal`
 17  echo "Diskpace 硬盘大小:" `lsblk | grep -E '^sda' | grep -Eo [0-9]+[[:upper:]]`

二、编写脚本实现每日将 /etc/ 目录备份到 /backup/etcYYYY-mm-dd中

脚本实现:需要另外添加crontab -e定时任务脚本

  1 #!/bin/bash
  2 #
  3 #*********************************
  4 #Auther:      xi
  5 #Date:        2024-12-26
  6 #FileName:    backup.sh
  7 #URL:         http://www.xxx.com
  8 #Description: test
  9 #Copyright(C):2024 All right
 10 #**********************************
 11 SOURCE_DIR="/etc"
 12 BACKUP_DIR="/backup/etc$(date+%Y-%m-%d)"
 13 mkdir -p "$BACKUP_DIR"
 14 cp -av $SOURCE_DIR $BACKUP_DIR

定时任务:

三、编写脚本显示当前硬盘中最大使用

脚本实现:

  1 #!/bin/bash
  2 #
  3 #*********************************
  4 #Auther:      xi
  5 #Date:        2024-12-26
  6 #FileName:    disk.sh
  7 #URL:         http://www.xxx.com
  8 #Description: test
  9 #Copyright(C):2024 All right
 10 #**********************************
 11 df -h | grep -E '^/dev/(sd.*)' | tr -s ' ' | cut -d' ' -f1,5 | sort -t' ' -k2 -rn

四、编写脚本显示正连接本主机的每个远程主机的IPv4地址和连接数,并按连接数从大到小排序

  1 #!/bin/bash
  2 #
  3 #*********************************
  4 #Auther:      xi
  5 #Date:        2024-12-26
  6 #FileName:    links.sh
  7 #URL:         http://www.xxx.com
  8 #Description: test
  9 #Copyright(C):2024 All right
 10 #**********************************
 11 netstat -nt | awk '/^tcp\>/ {print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值