Linux登录获取系统负载、内存、磁盘、监听信息脚本

操作步骤如下:

  1. 编辑vim /jiaoben/dynmotd.sh文件,拷贝下文脚本内容
  2. 赋予x执行权限 chmod +x /jiaoben/dynmotd.sh
  3. 将文件追加到profile中 echo /jiaoben/dynmotd.sh >> /etc/profile
  4. 重新登录服务器进行验证
# System load
    LOAD1=cat /proc/loadavg | awk {'print $1'}
    LOAD5=cat /proc/loadavg | awk {'print $2'}
    LOAD15=cat /proc/loadavg | awk {'print $3'}

MEMORY=free -mh | grep "Mem" | awk '{print "used:",$3,"/",$2,"( free: ",$4,")"}'
MEM_USAGE=free -m | grep "Mem" | awk '{printf("%3.1f%%", (($3/$2)*100))}'
DISK=df -Ph / | awk '/\// {print "used:",$3,"/",$2," ( free:",$4,")"}'
DISK_USAGE=df -h / | awk '/\// {print $5}'|grep -v "^$"

echo "
===========================================================================
- Release.............: cat /etc/redhat-release
- Kernel..............: uname -r
- Hostname............: uname -n
- Username............: whoami
- IP..................: hostname -I
- Login Users.........: Total users | wc -w user(s)
===========================================================================
- CPU usage...........: $LOAD1 - $LOAD5 - $LOAD15 (1-5-15 min)
- Memory..............: $MEMORY
- Memory usage........: $MEM_USAGE
===========================================================================
- Mem info:
free -mh

- Disk info:
df -h

- Net info:
netstat -ntpl
===========================================================================
"

版权声明:
作者:WangGaoli
链接:https://wanggaoli.com/3283.html
来源:王高利的个人博客
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>