How to test connectivity via SSH from the script?

How to check up on the remote machine SSH start. Ie if does not start then wait, and if you start, then copy to/from files via SCP.
September 19th 19 at 13:20
2 answers
September 19th 19 at 13:22
Solution
typically, when the program executed successfully, it returns exit code. successful, 0 (zero), any non-zero - failure
you can just run scp to copy. if ssh is not running, the result will be a failure
echo $?
thus you can run an infinite loop and trying to work with the server via sshusing scp while the result will not be 0. as soon as we get the 0 - exit of the cycle - in this case, the files will be uploaded
you can pause between attempts to connect in order not to hammer the server
Thank you! "$?" what was needed. have done so:

while true; do
sshpass -p 'retset' scp-r folder/* "user@host:/path/"
ANS=$?
if [ $ANS == 0 ]; then
echo "ok"
break
else
echo "timeout"
fi
sleep 1
done
echo "end script" - ericka.Stok commented on September 19th 19 at 13:25
September 19th 19 at 13:24
To connect:
ssh username@ip
After entering the command will ask for the password. Also optionally you can put the-p if the ssh on some custom port. Accordingly, if you have connected with SSH everything is OK.

With the csp it's simple. 2 examples below:
1. Copy the file "file.txt" from the remote server to your local computer.
scp user@remote.host:file.txt /some/local/directory

2. Copy the file "file.txt" from the local computer to a remote server.
scp file.txt user@remote.host:/some/remote/directory
if connected via ssh then the control will give ssh. the script will require the participation of polzovatelya - ericka.Stok commented on September 19th 19 at 13:27

Find more questions by tags SSHbash