I want to SSH over multiple server (host 1, host2 and host 3) and save output of multiple commands (cmd1, cmd2 etc) in file (output.properties) on local server. I know there are a few posts similar to this, but I a not sure where I am going wrong. Below is the code snippet.
folderPath="cd /usr/local/apps/tempdir"; echo $folderPath; eval $folderPath; # host 1 echo RepCard1=$(expr $(grep -r "sample text" * | wc -l) / 2) >> /usr/local/host1/tempdir/output.properties; # Server 2 ssh -T user@host2 <<EOF >>/usr/local/host1/tempdir/output.properties; #alias GetDuplicateCardStats="cd /usr/local/apps/tempdir" folderPath="cd /usr/local/apps/tempdir"; echo $folderPath; eval $folderPath; echo RepCard2=$(expr $(grep -r "sample text" * | wc -l) / 2); exit EOF . /usr/local/host1/tempdir/output.properties; echo "host 1" echo $RepCard1 echo "host 2" echo $RepCard2 # RepCard2 is always executed on Host 1 and print value from host 1
What is the mistake in the above script?