ssh remote command ls hangs when using '*'

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 Судьба - это Oracle Linux 7.5

1
задан 9 November 2018 в 18:53
1 ответ

Расширение подстановочных знаков bash работает таким образом, что / some / thing * в вашей команде всегда расширяется в вашей локальной системе, даже если есть ssh в начале строки. Неожиданно, но все же.

Для выполнения поставленной задачи всегда используйте кавычки: ssh user @ host 'ls / path / to / file *'

В успешном тесте: если в вашей системе нет / path / to / folder / file_000 * он отправляет ту же строку / path / to / folder / file_000 * на удаленный компьютер.

В вашем плохом тесте: если ваша система имеет / path / to / folder / file_some_name и / path / to / folder / file_yet_another , затем он отправляет эти строки на удаленный компьютер вместо / path / to / folder / file *

Во-первых, зависание может произойти в локальной системе при выводе списка локальных файлов - например, зависание на уровне файловой системы.

Во-вторых, если вы отправляете по сети текстуально более длинную строку, вы можете столкнуться с проблемой MTU ( максимальная единица передачи). Проблема с MTU остается незамеченной, если размер всех пакетов меньше MTU.

Предлагаемый тестовый пример

Для проверки только сетевой проблемы и только в одном направлении:

ssh user@host  'echo Type here some text that is longer than 1500 bytes > /tmp/delete_me'
2
ответ дан 3 December 2019 в 20:11

Теги

Похожие вопросы