The command
ssh -q -o "BatchMode=yes" user@host "echo 2>&1" && echo "OK" || echo "NOK"
will help in checking whether the SSH connection to peer IP is a success or not. But I am having only Peer IP so
ss开发者_如何转开发h -q -o "BatchMode=yes" peerIP 2>&1" && echo "OK" || echo "NOK"
doesnt work.
Anyone knows how can i solve it? A One-liner command is required and it should work on AIX, HP, Linux... any help or suggestion is very much appreciated.
Why do you mention awk ? Whatever, here a solution that works for me:
ssh USER@HOST 'env |grep SSH_CLIENT && echo "OK" || echo "NOK"'
When SSH is connected to the host, some environment variable will be set.
Also, when your connection to a remote host without using a User in the SSH URL, your current should be set by default. You can change that behavior in your */etc/ssh/ssh_config* . Maybe that will fix it.
Good luck
精彩评论