我使用的是 Ubuntu 16.04。我编写了一个基本的 bash 文件,可以自动将我登录到 SSH 服务器。如果 SSH 无法连接到服务器,是否有办法添加一条消息,提示“连接失败”?可能是命令if
?我已将文件放在GitHub。
添加脚本
#!/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
而sshpass -p "passwordhere" ssh -o StrictHostKeyChecking=no user@host
不是
if $(sshpass -p "passwordhere" ssh -o StrictHostKeyChecking=no user@host); then echo "Success!"; else echo "Bother. Didn't work."; fi