Q:

Gather Full GC count from remote machine via ssh with Shell

I have a file of server list, and all the servers in it are authorized to the machine which I have logged on. I want to gather Full GC count of all servers from file /some/path/gc.log with Shell. How can I do this?
servers.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

What done so far:
#!/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"

Part of 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] 

A:

I will assume that you want a text report of total GC for each host where total GC is defined the number of lines in the file gc.log on which the word Full appears.  In that case, use:
#!/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"

This produces output like:
Total GC for 192.168.1.101 is 3.

