0
#!/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?

2 Answers 2

2

Good to try is the IO redirection:

ssh [username]@[ip] "bash -s" > file.txt <<EOF
[...]
Sign up to request clarification or add additional context in comments.

Comments

2

Exit status of ssh is the exit status of the remote command so this should work:

( ssh [username]@[ip] [command] && echo success || echo failure ) > result.txt

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.