Atmesh Mishra Atmesh Mishra - 4 months ago 7
Bash Question

ssh to server, run commands and save output of commands on local machine using shell

#!/bin/sh
ssh [username]@[ip] "bash -s" <<EOF
if [condition]
then
echo "success"
else
echo "failure"
fi
EOF


After running these commands, I want to save the result (ie success/failure) in a file on local machine. How do I go about it?

Answer

Good to try is the IO redirection:

ssh [username]@[ip] "bash -s" > file.txt <<EOF
[...]
Comments