Linux Shell脚本收集Linux系统信息
时间:2020-03-05 15:31:42 来源:igfitidea点击:
在本教程中,脚本将获取有关Linux服务器的信息,例如登录的用户,正常运行时间,平均负载,可用内存,磁盘使用率。
该脚本有助于在一秒钟内查看有关服务器的所有信息。
如果需要从多个服务器中查找系统信息,管理员可以修改脚本位。
脚本运行命令w,uname,uptime,free和df。
从正常运行时间命令脚本中获取平均负载。
使用Shell脚本获取服务器信息
让我们检查shell脚本以查找服务器信息。
#!/bin/bash #clear console clear #just echo welcome messages echo "This is information provided byThis is information provided by ./system_info.sh . Program starts now. Hello, theitroad Today's date is Sunday, March 3 2013 22:31:43 +0200, this is week 09. These users are currently connected: theitroad This is Linux running on a i686 processor. This is the uptime information: 22:31:43 up 1:24, 2 users, load average: 0.45, 0.18, 0.07 Free memory: total used free shared buffers cached Mem: 3374792 1589476 1785316 0 96720 725652 -/+ buffers/cache: 767104 2607688 Swap: 4192924 0 4192924 Disk usage: Filesystem Size Used Avail Use% mounted /dev/sda1 42G 5,5G 35G 14% / tmpfs 1,7G 0 1,7G 0% /lib/init/rw udev 1,7G 168K 1,7G 1% /dev tmpfs 1,7G 160K 1,7G 1% /dev/shm /dev/sda6 184G 26G 149G 15% /home. Program starts now." echo "Hello, $USER" echo #print today's date echo "Today's date is `date`, this is week `date +"%V"`." echo #list of currently loged user via w command. echo "These users are currently connected:" w | cut -d " " -f 1 - | grep -v USER | sort -u echo #info about system with command uname and keys -m and -s echo "This is `uname -s` running on a `uname -m` processor." echo #info about uptime, using uptime command echo "This is the uptime information:" uptime echo #info about free memory via free command echo "Free memory:" free echo #info about disk usage echo "Disk usage:" df -kh echo
输出
以下是脚本输出。
##代码##