scp output as logfile

别说谁变了你拦得住时间么 提交于 2021-02-09 11:41:43

问题


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?

Thanks.


回答1:


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

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



回答2:


scp -v -i ec2key.pem username@ec2ip:/p/t/file ~/p/t/d/f/file >> something.log 2>&1

-v and 2>&1 will append your extended details (i.e. debug info) in the existing something.log file.




回答3:


How about (untested, compressing /path/to for readability):

(scp -i ec2key.pem username@ec2ip:/p/t/file ~/p/t/d/f/file ) 2>/p/t/textfile


来源:https://stackoverflow.com/questions/21205986/scp-output-as-logfile

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!