BASH 使用 ssh 时无法 运行 找到

BASH cannot run find when using ssh

与我之前的问题相关 -

当运行以下:

ssh remoteuser@1.2.3.4 find /home/remoteuser/logs -maxdepth 1 -type d

我得到:

bash: find: command not found

所以.. 看来我无法通过 ssh 进行查找?

我真的需要想出一种方法来检查以下位置的文件: /home/remoteuser/logs

供应商处理的日志将进入: /home/remoteuser/logs/存档

我确实需要查看文件是否已在日志中处理。

由于您的实际目标是确定给定目录中是否直接存在任何文件,因此不需要 find

考虑:

# this function is very careful to use only functionality built into POSIX shells.
rmtfunc() {
  set -- /home/remoteuser/logs/* # put contents of directory into $@ array
  for arg; do                    # ...for each item in that array...
    [ -f "$arg" ] && exit 0      # ...if it's a file that exists, success
  done
  exit 1                         # if nothing matched above, failure
}

# emit text that defines that function into the ssh command, then run same
if ssh remoteuser@host "$(declare -f rmtfunc); rmtfunc"; then
  echo "Found remote logfiles"
else
  echo "No remote logfiles exist"
fi

要诊断为什么 find 不起作用,请检查远程系统上的路径:

ssh remoteuser@host 'echo "$PATH"' # important: single-quotes on the outside!

...并检查 find 可执行文件是否实际存在于该 PATH 的任何目录中。