【问题标题】:Send SCP's stdout to Screen and STDERR to File将 SCP 的标准输出发送到屏幕并将 STDERR 发送到文件
【发布时间】:2012-07-22 01:55:49
【问题描述】:

有很多关于如何在使用 SCP 时重定向 out 和 err 的讨论,或者只是 stdout 本身,但我很好奇是否有人知道如何在 stdout 继续打印到屏幕时将 stderr 重定向到文件。

目前,如果我们像这样重定向stderr:

scp user@XXXX:*.txt  . 2>errfile.txt

stdout 上不显示任何内容,在 errfile.txt 中仅捕获错误和回显。

【问题讨论】:

  • 嗯,这正是你所做的。标准输出(进度信息)输出到您的终端,标准错误发送到 errfile.txt。顺便说一句,你最好保护第一个参数中的明星不被扩展:\*.txt。否则它将扩展到您所在计算机上的文件名,这不太可能是您想要的。
  • 我试过这个:scp user@XXX:/$PATH/test*。 2> /tmp/test ,使用 openssh 客户端并且它的工作原理,我已经在 sdout 上复制了所有文件,并在“/tmp/test”文件中拒绝了权限。 Sh -> dash 和 ssh 客户端:OpenSSH_5.3p1 Debian-3ubuntu7,OpenSSL 0.9.8k 2009 年 3 月 25 日

标签: shell stdout scp stderr


【解决方案1】:

这是它的工作原理

MPBAB:work anj$ cat test.sh
echo "Hello there"
echo "This is a test script"

badcommand
MPBAB:work anj$ ./test.sh 2> err.log
Hello there
This is a test script
MPBAB:work anj$ cat err.log
./test.sh: line 4: badcommand: command not found

如您所见,当test.sh 尝试调用badcommand 时,它会抛出错误。但是,两个echo 语句工作得很好,并显示在STDOUTSTDERR 登录到err.log

现在实现你尝试的方式-

MPBAB:work anj$ ./test.sh . 2>err.log
Hello there
This is a test script
MPBAB:work anj$ cat err.log
./test.sh: line 4: badcommand: command not found

以同样的方式工作。在您的情况下,我不得不认为您发出的 scp 命令不正确。 scp 需要 sourcedestination。像这样的东西(我想scptest.txt 到远程服务器)

MPBAB:work anj$ scp ./test.txt user@secure.server.com:/home/data 2>scperr.txt
user@secure.server.com's password: #<this is because I dont have the public key installed>
test.txt              100%  291     0.3KB/s   00:00    
MPBAB:work an$ cat scperr.txt
MPBAB:work anj$ 

所以你看,文件被复制了,它在STDOUT 中显示了test.txt 100% 291 0.3KB/s 00:00,因为没有错误scperr.txt 是空的。

【讨论】:

    猜你喜欢
    • 2019-01-21
    • 1970-01-01
    • 2012-06-29
    • 1970-01-01
    • 2015-02-19
    • 1970-01-01
    • 2021-11-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多