简体   繁体   English

在远程机器上查找文件

[英]find files on remote machine

Hi i am trying to execute the following command on a remote machine how do i do this 嗨,我正在尝试在远程计算机上执行以下命令,我该怎么做

ssh login.com find /nfs/repo/ -name ".user_repo.log" | \
  xargs cat | awk '{$NF=""; print $0}' |               \
  sed "1i Owner RepoName CreatedDate" | column -t

I get the following error message 我收到以下错误消息

 cat: /nfs/repo/new1/info/.user_repo.log: No such file or directory
 cat: /nfs/repo/new2/info/.user_repo.log: No such file or directory

cat command is trying to find file on the local system while these files are present on the remote machine.How do i handle this 当这些文件存在于远程计算机上时,cat命令正在尝试在本地系统上查找文件。我该如何处理

If you do: 如果您这样做:

ssh host command1 | command2

Then the shell will break at the pipe, so you'll get "ssh host command1" run as one command (ie remotely), and then "command2" run as another command (ie, locally.) You can force all the commands to run remotely by enclosing in quotes: 然后外壳将在管道处破裂,因此您将使“ ssh host command1”作为一个命令(即,远程)运行,然后使“ command2”作为另一个命令(即,本地)运行。您可以强制所有命令执行通过将引号括起来可以远程运行:

ssh host "command1 | command2"

Note, since you already have quotes in the command, you might have to get creative with escaping. 请注意,由于命令中已经包含引号,所以您可能必须通过转义来发挥创意。

Or, you might put all those commands in a short shell script and then just run the script: 或者,您可以将所有这些命令放在短壳脚本中,然后运行脚本:

ssh host myscript.sh

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM