Take the 2-minute tour ×

I use "scp" command in my shell script. How do I get the error log , if that command is not working.

This is how I am using it scp file username@servername:/specificdirectory/

share|improve this question
add comment

3 Answers

up vote 3 down vote accepted

If you encounter an error while running scp, try doing ssh first to the server, scp doesn't have a graceful handling of new keys and ssh is more verbose with error reporting by default.

To get a more detailed log of what is happening, try running it with -v:

scp -v file username@servername:/specificdirectory/

You must also remember that path starting with / are absolute, not relative to your home directory, as such you may want to try:

scp file username@servername:specificdirectory/
share|improve this answer
I am using scp in a script , can i still use -v option and try to get the detail log in a log file? –  yogsma Oct 5 '10 at 18:19
-v writes debug information to STDERR. so if you redirect STDERR output to a log file then all debug info will be there. –  Casual Coder Oct 5 '10 at 18:26
thanks, I am using that way now. –  yogsma Oct 5 '10 at 19:13
add comment

A good way to get debug output with bash is to use set -x. Typically, any results will be output to STDOUT or STDERR. How that is captured will depend on how your script is being executed. As per the bash(1) manpage:

      -x      After  expanding each simple command, for command, case
              command, select command,  or  arithmetic  for  command,
              display the expanded value of PS4, followed by the com-
              mand and its  expanded  arguments  or  associated  word
share|improve this answer
add comment

Usually programs in unix environment writes errors to, well, standard error output. so you can execute your command like this:

scp -v file username@servername:/specificdirectory/ 2> scp_error.log   
share|improve this answer
add comment

Your Answer


