scp输出作为日志文件 [英] scp output as logfile
问题描述
我对使用scp相对较新-我正在尝试通过ec2做一些简单的事情-类似于以下内容:
I am relatively new to using scp - and I am trying to do some simple stuff over ec2 - something like the following:
scp -i ec2key.pem username@ec2ip:/path/to/file ~/path/to/dest/folder/file
我想要的是上述命令的日志(即屏幕输出到文本文件)-有没有办法实现这一目标?
What I would like to have is the log of the above command (i.e the screen output to a text file) - Is there a way to achieve this?
谢谢.
推荐答案
如果您使用冗长的( -v
)参数.否则, scp
将抑制输出,因为它期望将其 stdout
连接到终端.但是随后您获得了太多信息,而您可以通过 grep
摆脱这些信息:
You can redirect both outputs (stdout, stderr) of the command with &>
provided you use the verbose (-v
) argument. Otherwise, scp
will suppress the output as it expects its stdout
to be connected to a terminal. But then you get too much information, which you can get rid of with grep
:
scp -v -i ec2key.pem username@ec2ip:/path/to/file ~/path/to/dest/folder/file |& grep -v ^debug > file.log
如果要同时输出到屏幕和文件,请使用 tee
If you want to have the output both to the screen and the file, use tee
scp -v -i ec2key.pem username@ec2ip:/path/to/file ~/path/to/dest/folder/file |& grep -v ^ debug tee file.log
这篇关于scp输出作为日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!