linux - 嵌套的 Shell 脚本

标签 linux shell unix

shell脚本中的以下代码有什么问题:

下面的代码引发了意外的 else 错误:

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

下面给出/usr/bin/sftp not found 错误:

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

问候,

最佳答案

您在第二个 if 语句之后缺少 then

应该是

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

至于第二个命令,要么没有安装 sftp,要么它不在 /usr/bin 中。

运行 which sftp 找出它的位置。

关于linux - 嵌套的 Shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13100251/

相关文章:

c++ - 如何将用 linux 编写的 std::wstring 读入 windows

bash - 如何将文件的内容与列的最后一个数字的增量连接起来

linux - 逐行读取文件->在另一个文本文档中搜索每一行,如果匹配,则输出到另一个文本文件

python - 在python脚本中获取路径

unix - 如何在 MacOS 上加载系统范围的守护进程

python - pip 在标准输出中打印垃圾消息

c - 使用 sigaction() 实现 siginterrupt()?

php - 如何在 shell_exec 函数中包含 shell 命令?

linux - terminfo 延迟/填充如何在 TTY 中实现?

linux - Winsock2 listen() 是如何阻塞的?