How to use SSH to run a local shell script?
That will prompt you for password, unless you have copied your hostA user’s public key to the authorized_keys file on the home of user .ssh’s directory. That will allow for passwordless authentication (if accepted as an auth method on the ssh server’s configuration)
Why do I only see the first line in do _ work.sh?
In do_work.sh, I run a couple of ssh commands. The problem is that do_work.sh runs ssh commands and by default ssh reads from stdin which is your input file. As a result, you only see the first line processed, because ssh consumes the rest of the file and your while loop terminates.
When to use ssh-n in shell while loop?
If you have nested loops using read, use a different file descriptor for each one (9,8,7,…). ssh -n option prevents checking the exit status of ssh when using HEREdoc while piping output to another program. So use of /dev/null as stdin is preferred.
How to prevent ssh from reading from stdin?
To prevent this, pass the -n option to your ssh command to make it read from /dev/null instead of stdin. More generally, a workaround which isn’t specific to ssh is to redirect standard input for any command which might otherwise consume the while loop’s input.
How to run SSH on a remote machine?
Try running ssh user@remote sh ./script.unx. Assuming you mean you want to do this automatically from a “local” machine, without manually logging into the “remote” machine, you should look into a TCL extension known as Expect, it is designed precisely for this sort of situation.
How to run a command in background using SSH and TTY?
You should find that the prompt returns immediately, and that concat.sh is running on the remote machine. I’ll explain some of the options: ssh -t makes a TTY. screen needs this.
When does my-script.sh end in shell?
This, of course, depends on screen, and lets you attach later, if you ever want stdin or stdout. Screen will terminate itself when my-script.sh ends. Below is a much more common decision that required some efforts to find, and it really works for me: