I am trying to automate some things on remote Linux machines using bash scripts on a Linux machine and have a working command (brackets are a relic from cmd concatenations):
(ssh -i /path/to/private_key user@remoteHost 'sh -c "echo 1; echo 2; echo 3; uname -a"')
But if the ampersand is concatenated to run in the background, it seems to be executed, but the output is not printed, neither to stdout nor to stderr, and even redirecting to the file (inside curly brackets) does not work ...
(ssh -i /path/to/private_key user@remoteHost 'sh -c "echo 1; echo 2; echo 3; uname -a"') &
By the way, I am running the ssh dropbear v0.52 client in BusyBox v1.17.4 on Linux 2.4.37.10 (TomatoUSB is built on WRT54G).
Is there any way to get the result? What is the reason for this behavior?
EDIT:
For convenience, here you can find useful ssh information (on my TomatoUSB):
Dropbear client v0.52 Usage: ssh [options] [ user@ ]host[/port][,[ user@ ]host/port],...] [command] Options are: -p <remoteport> -l <username> -t Allocate a pty -T Don't allocate a pty -N Don't run a remote command -f Run in background after auth -y Always accept remote host key if unknown -s Request a subsystem (use for sftp) -i <identityfile> (multiple allowed) -L <listenport:remotehost:remoteport> Local port forwarding -g Allow remote hosts to connect to forwarded ports -R <listenport:remotehost:remoteport> Remote port forwarding -W <receive_window_buffer> (default 12288, larger may be faster, max 1MB) -K <keepalive> (0 is never, default 0) -I <idle_timeout> (0 is never, default 0) -B <endhost:endport> Netcat-alike forwarding -J <proxy_program> Use program pipe rather than TCP connection
Correction after 1 day:
Brackets do not hurt, with and without the same result. I wanted to put ssh authentication in the background, so the -f option is not a solution. Interesting note: if an unexpected parameter (for example, -v ) is specified, the error message WARNING: Ignoring unknown argument '-v' is displayed - even if it is placed in the background, so getting output from background processes usually works in my environment.
I tried the regular x86 Ubuntu ssh client: it works. I also tried dbclient on x86 Ubuntu: works too. So this problem seems to be specific to TomatoUSB build - or inside "dropbear v0.52" - this is an unknown fix between the build in TomatoUSB and the one provided by Ubuntu (the difference in the help output is only a double window buffer default reception on Ubuntu) ... how can a process know if it was placed in the background? Is there a solution to the problem?