scp is not working through sh script

Hi All,

I am generating a ~ delimited file from oracle table and then transfer it to another server through scp.

 
if [ -f $COM_DIR/ABC.txt ]
then
 scp $COM_DIR/ABC.txt unix.nam.nsroot.net:/home/magna/dum/ABC.txt 
else
 echo "File does not exist, please check" >>$LOG
fi

The script generates the file, but not able to deliver it to another server. To check what is the problem with scp command, i have tried to redirect the output to the LOG file like...

 
if [ -f $COM_DIR/ABC.txt ]
then
 scp $COM_DIR/ABC.txt unix.nam.nsroot.net:/home/magna/dum/ABC.txt >> $LOG
else
 echo "File does not exist, please check" >>$LOG
fi

but still it is not working.

While i executed only the scp command on command prompt, it works. Can someone tell me what could be a problem?

I too tried with scp in script and it got work,check the returned error.
And one more thing you can not capture the error by using '>>'.It is used to redirect the stdout to a file not stderr.

"It's not working" is about as useful as telling your doctor "it hurts".

What error messages do you get in your logfile (which you should redirect stderr to too, using '2>>$LOG')? Are you running the script as your user, or as a different id? By hand, or via an automated mechanism like cron?

Is it producting any error message.?
It seems your script looks okay...

The problem is it is not producing any error message.

use -v option to debug

scp -v  $COM_DIR/ABC.txt unix.nam.nsroot.net:/home/magna/dum/ABC.txt >> $LOG


  -v                      Verbose mode. Causes scp and  ssh(1)
                             to  print  debugging  messages about
                             their progress. This is  helpful  in
                             debugging   connection,  authentica-
                             tion, and configuration problems.
if [ -f $COM_DIR/ABC.txt ]
then
 scp $COM_DIR/ABC.txt unix.nam.nsroot.net:/home/magna/dum/ABC.txt 1> /usr2/spool/out1.txt 2> /usr2/spool/out2.txt
else
 echo "File does not exist, please check" >>$LOG
fi

Note: Change log path name.

specify the full path of scp

something like

/bin/scp

cheers,
Devaraj Takhellambam

I doubt that very much. But just in case, replace the line

scp $COM_DIR/ABC.txt unix.nam.nsroot.net:/home/magna/dum/ABC.txt >> $LOG

with

scp $COM_DIR/ABC.txt unix.nam.nsroot.net:/home/magna/dum/ABC.txt >> $LOG 2>&1
[ $? -ne 0 ] && echo "Error with SCP: $?" >> $LOG

Make sure you copy them verbatim, as both are new to your script.