Shell Script Return Code SCP 1

I use the scp shell script command to move one file from one server to another using ssh. My command looks like this:

scp -P 23 -i $TEST_SSHKEY $DESTINATION_PATH/$FILETOCOPY $USER_ID@ $SERVER_BOX: 

The file is copied, but scp returns the return code as 1.

Why is this happening and what is the solution for this?

+4
source share
2 answers

G'day

Try turning verbose mode (-v) on to see more details about what is happening, rather than just looking at return code 1, which means "something bad happened."

+1
source

I have the same problem. The problem is that the server at the remote end does not send an exit code. Compare these transaction excerpts.

First reasons $? = 1 $? = 1 :

 debug1: Sending command: scp -v -f /cfg/running-config Sink: C0644 3398 running-config running-config 100% 3398 3.3KB/s 00:00 debug1: channel 0: free: client-session, nchannels 1 debug1: fd 0 clearing O_NONBLOCK debug1: fd 1 clearing O_NONBLOCK Connection to xxxxx closed by remote host. Transferred: sent 2576, received 5216 bytes, in 1.9 seconds Bytes per second: sent 1346.9, received 2727.3 debug1: Exit status -1 

The second reason $?=0 :

 debug1: Sending command: scp -v -f /cfg/running-config Sink: C0644 3940 running-config running-config 100% 3940 3.9KB/s 00:00 debug1: client_input_channel_req: channel 0 rtype exit-status reply 0 debug1: channel 0: free: client-session, nchannels 1 debug1: fd 0 clearing O_NONBLOCK debug1: fd 1 clearing O_NONBLOCK Connection to xxxxx closed by remote host. Transferred: sent 2624, received 5984 bytes, in 1.3 seconds Bytes per second: sent 2026.8, received 4622.2 

These are two HP switches on different firmware versions. The first is very old; the second is new and correctly returns exit-status reply 0 client.

+1
source

All Articles