I am attempting to ssh into a server by using a bash script from MacOSX.
#!/bin/bash spawn ssh username@gatewayserver expect "password" send "Mypassword\r" interact spawn ssh username@storageserver expect "password" send "Mypassword\r" interact cd /path spawn scp -r retrievedfolder username@gatewayserver:/path/ expect "password" send "Mypassword\r" interact exit exit spawn scp -r username@gatewayserver:/path/retrievedfolder . expect "password" send "Mypassword\r" interact spawn ssh username@gatewayserver expect "password" send "Mypassword\r" interact rm -r retrievedfolder/ exit mv -nv -- "$retrievedfolder" "$retrievedfolder.$(date +%Y%m%d)" mv /retrievedfolder /backup If you can follow the probably redundant code, the goal was to log into the gateway server to get to the storage server. cd to the appropriate folder. secure copy the folder i want to a directory on the gateway server, and then copy the file from the gateway server to the desktop. Then I want to remove the retrieved folder from the gateway server (storage limitations) and move the copied folder to a folder on the desktop with the current date appended to the end of the file name. I think that most of what I have written should work if I were running linux but bash on MacOS isn't recognizing spawn send or interact and it is looking for a file or directory after expect.
After some help from Stephen Kitt and webKnjaZ, my code looks more like this:
#!/bin/bash ssh username@gatewayserver ssh username@storageserver 'ssh username@storageserver; cd /path/ ; scp -r retrievedfolder username@gatewayserver:/path/ exit exit' scp -r username@gatewayserver:/path/retrievedfolder . ssh username@gatewayserver rm 'rm -r retrievedfolder/ exit' mv -nv -- "$retrievedfolder""retrievedfolder" "$retrievedfolder"retrievedfolder.$(date +%Y%m%d)" mv /retrievedfolder.$(date +%Y%m%d)/ backup/ After correctly setting up passwordless SSH it almost works correctly. Since I cannot reach the "storageserver" without first logging into the gateway server, I cannot reference the "storageserver" within bashWithout ssh -tt it gives me an error message: "Pseudo-terminal will not be allocated because stdin is not a terminal". The command to login toWith ssh -tt it stops at the "storageserver"command prompt once I am logged in to the gateway is storageserver-login but that command needs to be executed oninto the gatewaysecond server prompt, and not treated likewhen I use ssh -T it is coming from my desktophangs. Do I need to write another script that is saved on the server and have(probably in the desktop bash script run it? If sosame spot, how?but just not visible)