Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

rcp does not return an exit code 2

Status
Not open for further replies.

GrahamBright

Programmer
Oct 31, 2003
65
AT
Hi,

I am trying to use RCP to transfer files to a remote sever.

All is fine using the following with the following : -

rcp $FILE $HOSTNAME:$BASE_RCP_DIR/$HOSTNAME/$DATE


and the exit code 0 is returned as seen in $?

However if I try to use copy a file which is not present no exit code is returned.

I need the exit code so I can take some action when rcp fails.

Thanks in advance,

Graham.
 
What unix flavour?
It works fine (or not) with RC=0 (or RC=1) on AIX...


HTH,

p5wizard
 
if I try to use copy a file which is not present
I know this doesn't answer your question but I wouldn't even try copying a file that doesn't exist. For example
Code:
if [ -f $FILE ]
then
  if rcp $FILE $HOSTNAME:$BASE_RCP_DIR/$HOSTNAME/$DATE
  then
    echo it worked
  else
    echo it failed
  fi
  echo $FILE not found
fi
I, like p5wizard, use AIX on which this works perfectly

Ceci n'est pas une signature
Columb Healy
 
Just a little missing
Code:
if [ -f $FILE ]
then
  if rcp $FILE $HOSTNAME:$BASE_RCP_DIR/$HOSTNAME/$DATE
  then
    echo it worked
  else
    echo it failed
  fi
[fuchsia]else[/fuchsia]
  echo $FILE not found
fi
On my AIX box, the return code is 2 when the file is not found.


Jean-Pierre.
 
Hi,

Thanks for all your answers:

I found the problem: -

rcp does of course generate a return code(0, 1), however silly me I was parsing out files resulting in my rcp call not receiving anything :(((
########################################

FILE_LIST=`ls $BASE_DIR/$DATE | grep -v "out.done"`

#check for zero files to transfer
if [ "$?" -ne "0" ]; then
log "No new files to transfer exiting ...."
exit
fi
#

log "Processing Files $FILE_LIST"

for FILE in $FILE_LIST

do
#Process the file

#Transfer file to stats server
log "Transfering File is $FILE to stats_server"
rcp $FILE $HOSTNAME:$BASE_RCP_DIR/$HOSTNAME/$DATE

#echo "The return code is $?"
#if [ "$?" -ne "0" ]; then
#echo "Sorry, cannot find file $FILE"
#exit
#fi

mv $FILE $FILE.done

#################################
 
There is always more than one way to skin a cat but how about
Code:
COUNT=0
for FILE in $(ls $BASE_DIR/$DATE|grep -v out.done)
do
  if rcp $FILE $HOSTNAME:$BASE_RCP_DIR/$HOSTNAME/$DATE
  then
    mv $FILE $FILE.done
    (( COUNT += 1 ))
  else
    log rcp for $FILE failed
  fi
done
log $COUNT files transferred
You're assumign that if the rcp fails it's because it couldn't find the file but you know it's there from the ls unless you've got some sort of race condition. The rcp is more likely to fail for network reasons (always blame the network!) than file not found.

Ceci n'est pas une signature
Columb Healy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top