1.前提:
运行脚本的机器上,ssh免密登录需要编译的server,被统计的server 使用同一帐号。
2.登录并执行:
使用ssh 登录并执行 who , uptime 等实时信息,并赋值给变量,在运行脚本的机器上打印出来。
脚本示例:
#!/bin/bash servers=( 172.0.1.2 \ 172.0.1.3 \ 172.0.5.50) for i in "${servers[@]}" do _users=$(ssh relmgr@$i "who | cut -d' ' -f1 | sort | uniq | wc -l" 2> /dev/null) ld_av=$(ssh relmgr@$i "uptime | cut -d',' -f4-6" 2> /dev/null) _date=$(date) echo -e "\n-------------------------" echo -e "Report for: $i" echo -e "-------------------------" echo -e "Date: ${_date}" echo -e "Number of active users: ${_users}" echo -e "Load average:${ld_av}\n" done
No Leanote account? Sign up now.