Need help with executing and deleting remote bash script via a local bash script

Posted by kenja on Server Fault See other posts from Server Fault or by kenja
Published on 2010-06-17T22:58:39Z Indexed on 2010/06/17 23:03 UTC
Read the original article Hit count: 1039

Filed under:

I am trying to create a bash script that will scp a script to a remote server, ssh (using an ssh key that is already installed) to the remote server, execute the uploaded script, and then delete the remote script when it is finished. I'm not clear how to run an ssh session inside a bash script. Here are the commands I use to do it from the command line:

scp my_script.sh [email protected]:/usr/home/user/
ssh [email protected]
>sh my_script.sh
>rm myscript.sh
>exit

How do I script the ssh portion of my command list? Thanks!

© Server Fault or respective owner

Related posts about bash