Linux登录获取系统负载、内存、磁盘、监听信息脚本
操作步骤如下:
- 编辑
vim /jiaoben/dynmotd.sh
文件,拷贝下文脚本内容 - 赋予x执行权限
chmod +x /jiaoben/dynmotd.sh
- 将文件追加到profile中
echo /jiaoben/dynmotd.sh >> /etc/profile
- 重新登录服务器进行验证
# 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.........: Totalusers | 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
=========================================================================== "