I am not sure what sample.sh
is supposed to do, but I understand that you are trying to capture what is logged by this script.
I would try several solutions:
ssh -T [email protected] "bash /tmp/sample.sh >> result.txt"
This should save your output in your remote server. Then you could copy this file from remote to local using:
scp [email protected]:/remote/dir/result.txt /local/dir/
More context: Copying files from server to local computer using ssh
If you are choosing this solution, you could also consider to write your result.txt
directly from your script, and keep the console output for important logging purpose.
Another Solution I could think of would be to use
ssh [email protected] "bash /tmp/sample.sh" > result.txt
With this solution you will redirect your output directly to your local machine.
But you will need to delete the ssh "-T" option. And you will run into other problems with Jenkins. So this might not fit you.
ssh -T
Disables pseudo-tty allocation, what sounds like your problem's root cause. (https://docs.oracle.com/cd/E36784_01/html/E36870/ssh-1.html)