Question

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.

Était-ce utile?

La 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

Autres conseils

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.

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
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top