0

I am using Ubuntu 16.04. I have written a basic bash file which automatically logs me into my SSH server. Is there a way to add a message which says "Connection failed" if SSH can't reach the server? Possibly an if command? I have put the file on GitHub.

Added script

#!/bin/sh
#I wrote this little bash script for people.
#It's just for people that don't know how to make an auto login script for SSH.
clear
echo "Welcome, $USER !"
echo "Connecting to SSH server..."
sshpass -p "passwordhere" ssh -o StrictHostKeyChecking=no user@host
  • 1
    Post your script. ssh ... || printf "Connection failed" – Panther May 18 '16 at 16:08
  • It's here. – runnerbeany May 18 '16 at 16:10
0

Instead of sshpass -p "passwordhere" ssh -o StrictHostKeyChecking=no user@host, make it

if $(sshpass -p "passwordhere" ssh -o StrictHostKeyChecking=no user@host); then echo "Success!"; else echo "Bother.  Didn't work."; fi
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.