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