[英]Shell script nested if
What is wrong with the following code in shell script : shell脚本中的以下代码有什么问题:
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找不到错误:
/usr/bin/sftp –v -oPort=$SFTP_PORT -b $SFTP_BATCH_FILE $SOURCE_FUNCTIONAL_ID@$REMOTE_SERVER_PROD >> $LOG_FILE 2 >> $LOG_FILE
Regards, 问候,
Chai 柴
You are missing the then after the second if statement. 你在第二个if语句之后错过了那个 。
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
. 对于第二个命令,未安装sftp或者它不在
/usr/bin
。
Run which sftp
to find out where it is. 运行
which sftp
找出它的位置。
if [[ $result -eq 4 || $result -eq 5 ]];
You forget the 'then' after the if construct. 你忘记了if构造之后的'then'。
When it is not found, check if sftp is found in the path. 如果找不到,请检查路径中是否找到sftp。
There are two errors. 有两个错误。 The syntax error is the missing
then
. 语法错误是缺失的
then
。 The other error is that this should be a case
statement: 另一个错误是这应该是一个
case
语句:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.