Linux – ssh remote command ls hangs when using ‘*’

linuxoracle-linuxssh

i'm having a problem with remote command in ssh.

The following commands run just fine:

ssh remote_server ls /path/to/folder/

(list all files of the folder – OK)

ssh remote_server ls /path/to/folder/file_000*

(wildcard match one file of the folder – OK)

The following command hangs:

ssh remote_server ls /path/to/folder/file*

(wildcard matchs some of the files – HANGS)

ssh remote_server ls /path/to/folder/*

(wildcard matchs all the files – HANGS)

The remote folder does not have a unreasonable amount of files: about 50, 40 of them would match 'file*' regex.

Running ssh with -vvv flag gives me the following output

[...]
debug1: Authentication succeeded (publickey).
debug1: channel 0: new [client-session]
debug3: ssh_session2_open: channel_new: 0
debug2: channel 0: send open
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug3: Wrote 136 bytes for a total of 2469
debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0
debug2: callback start
debug2: client_session2_setup: id 0
debug1: Sending environment.
debug3: Ignored env HOSTNAME
debug3: Ignored env SHELL
debug3: Ignored env TERM
debug3: Ignored env HISTSIZE
debug3: Ignored env USER
debug3: Ignored env LD_LIBRARY_PATH
debug3: Ignored env LS_COLORS
debug3: Ignored env ORACLE_SID
debug3: Ignored env ORACLE_BASE
debug3: Ignored env MAIL
debug3: Ignored env PATH
debug3: Ignored env PWD
debug1: Sending env LANG = en_US.UTF-8
debug2: channel 0: request env confirm 0
debug3: Ignored env HISTCONTROL
debug3: Ignored env SHLVL
debug3: Ignored env HOME
debug3: Ignored env LOGNAME
debug3: Ignored env CLASSPATH
debug3: Ignored env LESSOPEN
debug3: Ignored env ORACLE_HOME
debug3: Ignored env G_BROKEN_FILENAMES
debug3: Ignored env OLDPWD
debug3: Ignored env _
debug1: Sending command: ls /u01/app/oracle/backup/rman/*
debug2: channel 0: request exec confirm 1
debug2: fd 3 setting TCP_NODELAY
debug2: callback done
debug2: channel 0: open confirm rwindow 0 rmax 32768
debug3: Wrote 152 bytes for a total of 2621
debug2: channel 0: rcvd adjust 2097152
debug2: channel_input_status_confirm: type 99 id 0
debug2: exec request accepted on channel 0

in which point, hangs.

Any ideas?

Source is Oracle Linux 6.9
Destiny is Oracle Linux 7.5

Best Answer

The bash wildcard expansion works this way that /some/thing* in your command is always expanded on your local system, even if there is ssh at the beginning of the line. Unexpected, but still.

To accomplish your intended task, always use quotes: ssh user@host 'ls /path/to/file*'

In your successful test: if your system does not have /path/to/folder/file_000* it sends the same string /path/to/folder/file_000* to remote.

In your bad test: If your system has /path/to/folder/file_some_name and /path/to/folder/file_yet_another then it sends these strings to remote instead of /path/to/folder/file*

First of all the hang may be on the local system during listing local files - such as hang at the filesystem level.

Secondly, as you send a textually much longer string through the network, you might hit the MTU problem (maximum transfer unit). The MTU problem goes unnoticed if all packets are smaller than the MTU.

Suggested test case

To test for only network problem and only in one direction:

ssh user@host  'echo Type here some text that is longer than 1500 bytes > /tmp/delete_me'