JohnJ
JohnJ

Reputation: 7056

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.

Upvotes: 3

Views: 12214

Answers (4)

Kyo
Kyo

Reputation: 101

Example if you want to combine scp folder transfer with nohup:

touch /tmp/scp_nohup.log && nohup scp -v -r -o 'ProxyJump username1@ip1:port1' username2@ip2:/remote_path /local_path > /tmp/scp_nohup.log |& tail -F -s 0.5 /tmp/scp_nohup.log | grep -v debug

Upvotes: 0

Kushal
Kushal

Reputation: 3

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.

Upvotes: 0

damienfrancois
damienfrancois

Reputation: 59260

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

Upvotes: 3

abligh
abligh

Reputation: 25169

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

Upvotes: -1

Related Questions