Search code examples
linuxsshscp

scp output as logfile


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.


Solution

  • 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