I use the SSH client Prompt on my phone to access my servers and local machine. This is convenient enough; but sometimes, I want to run a single command and get out. This is really easy with the "Startup Command" field.

I start on the machine I want to run the command. I create an alias (or function) that will execute the command and then exit. For example, I already have an unmount_all script, which unmounts all external hard drives from my laptop. So I'll add this alias to my .zshrc file1:

alias unmount_all_and_exit='unmount_all && exit'  

Notice the && exit. This means that after the command of your choice has been run, the terminal will close (if the command exited successfully).

Now, in Prompt2, I create a new server:

Then, under "Server Settings", I can call the new command I just created in "Startup Command":

Now, when I tap that server in the server list, it will connect and automatically run the command. Then, because of exit, the connection will close as soon as the command finishes. It's one tap to run a script on your remote machine.

  1. Or .bashrc, or whatever shell you use

  2. I'm sure other SSH apps have a "startup command" feature.