SCP fails sometimes

Hi,

I got a unix script which copies a file from my AIX machine to a file server using SCP command. I am calling this script 3 times in my process after a time interval say 5mins. My issue here is like most of the time its not sending the file at the first time run while other 2 will work fine. I have found that the files are getting created, only issue is with the SCP.

I tried scp -v (verbose mode) and redirected to a log file. But its not writing anything to the logfile if it doesnt copy the file.

Can anyone put some light on this issue.

Thanks
Vipin C

Are the two machines on the same subnet or connected via routers?

Try doing a "ssh remotehost uname" or similar prior to the first "scp" just to confirm that the ARP tables are up to date.

Hi Porter,

Can you explain a little bit more. Because I am completely new to this networking scenarios evenif i hav worked with some small unix scripts. And what is this 'uname' stands for?

thanks in advance,
Vipin C

The 'uname' thing is purely something to run on the remote host so that you know you were able to talk to it. It could be *any* simple command that takes no stdin and executes quickly.

The problem I am trying to solve is you say that the 2nd scp works but not the first, this may be because the client has not managed to establish a network path to the remote server, hence running a command prior to confirm we do have connectivity with the remote host prior to doing the "scp" transfers.

As porter suggested, first get the connectivity through. Once that is done and still it does not work try to see if the ssh/scp processes get hung up somehow(I have seen that happen on Solaris). Check for the ssh version on your box and probably a patch for that version might fix the problem.
Also, first try to scp/ssh to that machine from the command line. Btw, is this a password based or key based authentication? Also, what "process" are you using to scp/ssh to the other machine?

Yes. It is a key based authentication. I can do the scp within a particular user login. So I guess, the public key for the user is saved in the secure file server to which Iam sending the file.
let me tell the actual scenario. I have developed the scripts from a test server and its working finewhen I executed there. Then I moved the scripts with my process to another server,scheduled to execute in a daily manner. When its executing automatically,this problem arises. But iam not quite sure its a connectivity issue, bcoz sometimes the first file copy correctly and miss the second one or third one.
This is the command I used for the same
scp_cmd="/usr/local/bin/scp -v $Target_file remoteservername:$Copy_directory";

Thanks
Vipin C

Hi guys....

iam still waiting for a reply......

Thanks

Try and run this to get the stdout to go to the log file:

Assuming:
scp_cmd="/usr/local/bin/scp -v $Target_file remoteservername:$Copy_directory"
Then:
$scp_cmd 2>&1 > /tmp/logfile.tmp 2>&1

After it runs, you should have something in the log file. Also, if you run the scp manually, it returns without any errors?

Yea man... I got the problem. Its like this...Iam opening an IP address and echoing the username and password for getting access to that machine. And from that machine only i am SCPing the file. This is because my username don't have the privilege to do SCP from my system. At this time when I echo the username and password if there is some problem in the network and the connection gets delayed ,then its just echoing username and password there itself.Its not waiting for password prompt.

We got an alternative method. I got another username which have the same privilege in my system. The thing we have to do is just to switch to that user and do the SCP. But the problem here is again the password prompt...i got the user password with us....but i am not able to echo it. There is other method like SUDO and EXPECT. But these things are not available in our system.....This is the scenario....Any hope????

Thanks in advance....

Vipin C

I've never been able to switch from one to another user successfully except for when switching from root. If you get it to work, I'd love to know how but I don't *think* it is possible.

Directly with only Unix script Its not possiblee,I guess... But there are some other options like sudo utility and EXPECT module in Perl.....Iam now checking with these.....But sudo seems unavailable in the system...and since its a secure server they won't allow us to install that too.....iam trying with the EXPECT module....till now, its didn't give good result....anyway i got hope......
will let you know once it succeeds..

Thanks,
Vipin C