通过带有 Shell 的 ssh 从远程计算机收集完整的 GC 计数



我有一个服务器列表的文件,其中的所有服务器都授权给我登录的机器。我想从使用 Shell 的文件/some/path/gc.log收集所有服务器的完整 GC 计数。我该怎么做?

服务器.txt

192.168.1.101 root
192.168.1.102 root
192.168.1.103 root
192.168.1.104 root
192.168.1.105 root

到目前为止做了什么

#!/bin/bash
while read line
do
    ip=$(echo $line | cut -f1 -d ' ')
    user=$(echo $line | cut -f2 -d ' ')
    # how to log on remote server and get Full GC count from /some/path/gc.log
done < "servers.txt"

GC的一部分.log

0.756: [Full GC (System) 0.756: [CMS: 0K->1696K(204800K), 0.0347096 secs] 11488K->1696K(252608K), [CMS Perm : 10328K->10320K(131072K)], 0.0347949 secs] [Times: user=0.06 sys=0.00, real=0.05 secs]  
1.728: [GC 1.728: [ParNew: 38272K->2323K(47808K), 0.0092276 secs] 39968K->4019K(252608K), 0.0093169 secs] [Times: user=0.01 sys=0.00, real=0.00 secs]  
2.642: [GC 2.643: [ParNew: 40595K->3685K(47808K), 0.0075343 secs] 42291K->5381K(252608K), 0.0075972 secs] [Times: user=0.03 sys=0.00, real=0.02 secs] 

我假设您想要每个主机的总 GC 的文本报告,其中定义了总 GC 中出现单词 Full 的文件gc.log的行数。 在这种情况下,请使用:

#!/bin/bash
while read host user
do
    echo "Total GC for $host is $(ssh "$user@$host" "grep 'Full' /path/to/gc.log | wc -l")."
done < "servers.txt"

这将产生如下输出:

Total GC for 192.168.1.101 is 3.

1- 使用 sshpassssh

sshpass -p <password> ssh <user>@<ip> 'cat /some/path/gc.log'

然后做任何你想做的事

2-使用期望脚本

最新更新