0

What is wrong with the following code in shell script :

Below code throwing unexpected else error:

if [ $result -eq 0 ];
then
  echo "SFTP completed successfully to Prod Remote Server" >> $LOG_FILE
else
    errorConnectToProd=1
   if [[ $result -eq 4 || $result -eq 5 ]];
  echo "FAILED to connect to Server. " >> $LOG_FILE

   else
 echo "FAILED to SFTP to  Remote Server. " >> $LOG_FILE
   fi
fi

Below line giving /usr/bin/sftp not found error:

/usr/bin/sftp –v -oPort=$SFTP_PORT -b $SFTP_BATCH_FILE $SOURCE_FUNCTIONAL_ID@$REMOTE_SERVER_PROD >> $LOG_FILE 2 >> $LOG_FILE

Regards,

Chai

3 Answers 3

2

You are missing the then after the second if statement.

It should be

 if [[ $result -eq 4 || $result -eq 5 ]];
 then
   echo "FAILED to connect to Server. " >> $LOG_FILE

As for the second command, either sftp isn't installed or it isn't in /usr/bin.

Run which sftp to find out where it is.

Sign up to request clarification or add additional context in comments.

Comments

0
if [[ $result -eq 4 || $result -eq 5 ]];

You forget the 'then' after the if construct.

When it is not found, check if sftp is found in the path.

Comments

0

There are two errors. The syntax error is the missing then. The other error is that this should be a case statement:

exec >> $LOG_FILE
case "$result" in
0)   echo "SFTP completed successfully to Prod Remote Server";;
4|5) errorConnectToProd=1
     echo "FAILED to connect to Server. ";;
*)   echo "FAILED to SFTP to  Remote Server. ";;
esac

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.