ssh "!command" escape sequence - does it work?

Karl Auer kauer at biplane.com.au
Fri Sep 11 12:58:52 UTC 2020


On Fri, 2020-09-11 at 13:11 +0100, Chris Green wrote:
> Yes, as it's supposed to be.  As you say though the rest of the
> !command escape seems to be, at the very least, not quite what one
> expects.  I've searched around quite a bit but I've not found
> anything very helpful.

I turned on debug with "-vvv", and:

otherhost:~$ [enter ~C] 
ssh> !echo freddy
debug3: Executing /bin/bash -c "echo freddy"
[enter]
otherhost:~$

I.e., nothing was actually echoed, but:

otherhost: ~$ /bin/bash -c "echo freddy"
freddy

myhost: ~$ /bin/bash -c "echo freddy"
freddy

This led me to think about what stderr and stdout might be when
executing a program deep in the bowels of ssh.

Now watch this :-)

myhost:~$ ssh otherhost
otherhost:~$ 
ssh> !echo boo > /tmp/boo.txt

otherhost:~$ exit
logout
Connection to otherhost closed.
myhost:~$ ls -la /tmp/boo.txt
-rw-r--r-- 1 kauer kauer 4 Sep 11 22:47 /tmp/boo.txt
myhost:~$ cat /tmp/boo.txt
boo

Ta daaa!

I.e., it was working all along. I bet that, like me, you were trying to
do something simple like local console output :-)

More investigation needed, but it makes sense not to allow you to
scribble on the remote's stdout, though it seems happy to scribble on
stderr.

The code that actually does this is a function called ssh_local_cmd in
sshconnect.c. It does a fork/exec sequence. You can get errors written
to syslog with the ssh "-y" option.

Regards, K.

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Karl Auer (kauer at biplane.com.au)
http://www.biplane.com.au/kauer

GPG fingerprint: 2561 E9EC D868 E73C 8AF1 49CF EE50 4B1D CCA1 5170
Old fingerprint: 8D08 9CAA 649A AFEF E862 062A 2E97 42D4 A2A0 616D







More information about the ubuntu-users mailing list