
Tengo un script zsh script.zsh server-name-here
que tiene un argumento, necesito probar ssh para eso server-name-here
y, si tiene éxito, continuar haciendo algo, si no, salir del script.
¿Cómo podemos lograr eso?
O puedo hacerlo con esta línea en zsh:
ssh user@$1 'exit' &> /dev/null if (( $? )); then ...
Respuesta1
Puede verificar si ssh
tuvo éxito directamente en un archivo if
, así:
if ssh maulinglawns@<host> 'exit'; then
echo "ssh success. Do stuff here..."
else
echo "ssh failed"
exit 1
fi
Nota: probado con Bash, pero debería funcionar también en Zsh.