The shell script uses "ten" to view multiple system CPU, specified process CPU, master / slave machine, and memory usage.
Requirements: view multiple machines to see multiple system CPU, specified process CPU, active and standby status, memory usage; and display on one machine
First: set ssh password-free login first
Ssh-keygen-t rsa playing'- f ~ / .ssh/id_rsa does not prompt to generate the secret key directly
Ssh-copy-id-I / .ssh/id_rsa.pub root@ip
Second: query script, which is copied to each machine
Scp / usr/local/src/cpu_men.sh root@ip: / usr/local/src/
Script content
#! / bin/bash
Cpu=top-bn1 | awk-F "[,:%]" / Cpu/ {print $2}'
Men_total=free-m | grep Mem | awk'{print $2}'
Men_used=free-m | grep Mem | awk'{print $3}'
Men_av=awk 'BEGIN {printf "% .0f\ n", (' ${men_used}'/'${men_total}') * 100}'
Num=ifconfig | awk'/ eth.:./ {print $1}'| wc-l
Syseth= "Lord"
[${num}-eq 0] & & syseth= "preparation"
IP=ifconfig | awk-F "[:] +" NR==2 {print $4}'
Pronum=ps aux | grep tdci | grep-Ev "$$| grep" | awk'{print $3}'| wc-l
Procpu=ps aux | grep tdci | grep-Ev "$$| grep" | awk'{print $3}'| xargs
# awk 'BEGIN {printf "%-20s%-10s%-10s%-10s%-20s\ n", "IP-", "status-", "CPU%-", "men%-", "procpu%-"}'
Awk 'BEGIN {printf "%-20s%-13s%-12s%-10s", "' ${IP}'", "'$syseth'", "'" ${cpu} "'",'"${men_av}"'}'
Echo "$procpu (${pronum}" tdic ")"
Third: overall query and display the script on a host: ssh_exec.sh
#! / bin/bash
Awk 'BEGIN {printf "%-20s%-10s%-10s%-10s%-20s\ n", "IP-", "status-", "CPU%-", "men%-", "procpu%-"}' arry= (
192.168.50.5
192.168.50.6
192.168.50.9
)
For ((iTuno / iarry = (
192.168.50.5
192.168.50.6
192.168.50.9
)
For ((iTun0) I [root@INTSVR-B src] # sh ssh_exec.sh > IP-status-CPU%-men%-procpu%- > 192.168.50.5 / 3.6101.3 0.5 (2 tdic) > 192.168.50.6 Master 8.4 12 24.8 2.4 (2 tdic) > 192.168.50.9 Master 4.5 30 0.7 (1 tdic) > 192.168.5010 standby 1.4 10 (0 tdic) > [root@INTSVR-B src] #