1

I have written a shell script to run other shell script on remote server(Shell script is running successfully on remote server). I want to capture output to some variable. Below is my code.

Please can anyone help me out.

#! /bin/sh
sshpass -p password ssh -T root@serverIP1 << EOF
sshpass -p password ssh -T root@serverIP2 << EOS
copyoutput=bash /opt/Shellscriptlocation/DiskSpace.sh
EOS
EOF
echo $copyoutput
Rajan
  • 41
  • 1
  • 8

1 Answers1

1

This should work for you by placing command substitution in outermost shell:

copyoutput=$(
sshpass -p password ssh -T root@serverIP1 << EOF
sshpass -p password ssh -T root@serverIP2 << EOS
bash /opt/Shellscriptlocation/DiskSpace.sh
EOS
EOF
)

echo "$copyoutput"
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • capturing output but also printing **logintoserver.sh: line 13: warning: here-document at line 9 delimited by end-of-file (wanted `EOF')** – Rajan Jan 03 '20 at 10:11