Redirecting the output of scp to a log file

Logging the output of scp (and similar commands) doesn’t work the straightforward way of a simple redirection because scp uses direct terminal codes and if it detects a redirection, it doesn’t output anything.

Fortunately there is a command called script which is able to simulate a terminal so the output could be recorded.

To trace the output of

scp $REMOTE_SERVER:~/test/test.file /dev/null

Wrap a script command around

# fetch the file, but don't store it locally
script -q -c "scp $REMOTE_SERVER:~/test/test.file /dev/null" 2>&1 | tee scpLog
# replace carriage return with newline
sed -i -e 's/\r/\n/g' scpLog

And your’e done

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s