我在执行以下 shell 脚本时收到错误 ./test1hc.sh[59]: [[[: not found in if condition

我在执行以下 shell 脚本时收到错误 ./test1hc.sh[59]: [[[: not found in if condition
exec > /apps/jobs/logs/healthcheck.log 2>&1

set -x

#!/bin/ksh

. ~/vdom.profile

db2 CONNECT to $DATABASE_MIF user $DBUSER_MIF using $DBPASS_MIF 

rm -r /apps/jobs/scripts/alerts/health_check/tempdata/*
cd /apps/jobs/scripts/alerts/health_check/tempdata/

emailalertgroup1='[email protected],[email protected]' 

param=`db2 -x "select dflt_value from param_def where param_group_id = 'COUNTFL'"`

param1=`db2 -x "select dflt_value from param_def where param_group_id = 'COUNTM'"`
    
amempty=`db2 -x "select con.router_id ,count(tran.MESSAGE_ID) as failure_count ,  con.router_description  from MIF_ROUTER_CONFIG con
LEFT JOIN tran_log tran ON con.ROUTER_ID = tran.ROUTER_ID where con.EXECUTION_FREQUENCY = '1' and tran.RESULT_CODE in (select dflt_value from param_def where param_group_id = 'STATUSCD') and tran.created_dttm > CURRENT_TIMESTAMP-$param1 MINUTE group by con.router_id,con.router_description HAVING count(tran.MESSAGE_ID)>=$param"`

db2 "select con.router_id ,count(tran.MESSAGE_ID) as failure_count ,  con.router_description  from MIF_ROUTER_CONFIG con
LEFT JOIN tran_log tran ON con.ROUTER_ID = tran.ROUTER_ID where con.EXECUTION_FREQUENCY = '1' and tran.RESULT_CODE in (select dflt_value from param_def where param_group_id = 'STATUSCD') and tran.created_dttm > CURRENT_TIMESTAMP-$param1 MINUTE group by con.router_id,con.router_description HAVING count(tran.MESSAGE_ID)>=$param" > /apps/jobs/scripts/alerts/health_check/tempdata/failure_count.txt

CurrentDay=$(date '+%A')
CurrentTime=$(date +"%H:%M")
    
cd /apps/jobs/scripts/alerts/health_check/tempdata/
 
    
if [[[ $amempty != "" ] -a [ $CurrentDay == "Friday" -a $CurrentTime -ge "10:00" ] ] -o [ [ $amempty != "" ] -a [ $CurrentDay == "Sunday" -a $CurrentTime -le "08:00" ]]]
    
then

echo "Hi Team, 

Please treat this with HIGH Priority. Below are the list of router with the failure count. Please login to MIF and take necessary action. Job did not fail."

cat failure_count.txt

else
    
    echo The message flow is normal..!! No action Required..!!

   fi
   
exit

答案1

不存在这样的运算符[[[。将您的代码粘贴到https://shellcheck.net/shellcheck或在本地计算机上部署以查看其他错误和建议。

您需要考虑的其他三个可能相关的问题,

  • 该行上方不应有任何代码#!/bin/ksh。这样的#!行应该始终是第一的任何脚本的行,用于标识运行该脚本的 shell
  • 确保脚本是可执行的,并且像程序一样调用它。 (例如,不要使用ksh script.sh而是使用./script.sh。这样就#!可以考虑该行。)
  • 为了保持一致性,不要将反引号求值(例如param=`db2 ...`)与嵌套求值(CurrentDay=$(date '+%A'))混合在一起。转向$( ...)在整个过程中只使用更现代的风格

相关内容