Apenas modifiquei seu script:
#!/bin/bash
# username to connect via ssh
USER=$2
# destination path/filename to save results to
DEST=$3
# source list of hostnames to read from
FILE=$1
[[ $# -ne 3 ]] && { echo -e "\nUsage: $0 <User> <ServerList> <LogFile>\n"; exit 1; };
func_ssh() {
local Ipaddr=$1
local Cmd="${@:2}"
local LogIt=${DEST}
ssh -q -o "BatchMode yes" -o "ConnectTimeout 5" -l $USER $Ipaddr "${Cmd}"
[[ $? -ne 0 ]] && printf "${Ipaddr}\tUnable to connect to host\n" >> ${LogIt}
}
GetTotalProcs="awk '/processor/{a++} END{print a}' /proc/cpuinfo"
GetMemoryDetails="free -g | sed -n -e '/^Mem:/s/^[^0-9]*\([0-9]*\) .*//p'"
# Iterate through line items in FILE and
# execute ssh, if we connected successfully
# run proc/info and free to find memory/cpu alloc
# write it to DEST path/file
# if we dont connect successfully, write the hostname
# and "unable to connect to host" error to DEST path/file
for srv in $(< $FILE );
do
echo -n "."
A="$( func_ssh $srv $GetTotalProcs )"
B="$( func_ssh $srv $GetMemoryDetails )"
echo "${srv} CPU: ${A} MEMORY: ${B}" >> ${DEST}
done
# All line items have been gone through,
# show done, and exit out
echo ""
echo "Done!"
echo "Check the list 'checkssh_failure' for errors."
exit 0