SSH/SFTP to remove server to execute scripts without being redirected to terminal

If you use a bash script to sftp/ssh into a remote terminal, you’ll notice the sftp prompt show up on the screen and the scripts beyond sftp will not be executed. You can enclose the remote server scripts in an EOM statement like this in order to do what you intend to.

#-- Go to the bottle server directory and get the existing files into the tars directory
cd /home/server/bottle/
tar -cvf /home/varun.verma/backups/provisioning-tars/bottle_server.tar *
cd /home/varun.verma/backups/provisioning-tars/
sftpgs <<EOM
cd /home/admin/dev_tar
put bottle_server.tar

sshgs <<EOM
cd /home/admin/dev_tar/
tar -xvf bottle_server.tar
rm bottle_server.tar

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s