通过 cron 调用 shell 脚本时,wait 命令被忽略或不起作用

通过 cron 调用 shell 脚本时,wait 命令被忽略或不起作用

我们需要监控 oem 代理状态,执行 sh .sh 时脚本运行正常,获取 oem 代理状态需要 55 秒才能将输出写入文件,我已使用该命令执行后端并等到该命令完成,但当脚本通过 cron 安排时它不起作用,它不会等到该命令完成

感谢任何在这方面的帮助

以下是 crontab 条目

########################OEM Script Monitoring#################################
0,10,20,30,40,50 * * * * /export/home/oraoem/scripts/emck.sh  > /dev/null 2>&1

-- cat emck.sh
#!/bin/bash
cd /export/home/oraoem/scripts
DBALIST="[email protected]"; export DBALIST
rm -f agent.exist
ps -ef | grep emagent | grep -v grep  > agent.exist
if [ -s agent.exist ]
then
cd $MY_AGENT_HOME/bin
./emctl status agent > /export/home/oraoem/scripts/agent.txt & echo $!
wait $!

grep "Number of XML files pending upload" /export/home/oraoem/scripts/agent.txt > /export/home/oraoem/scripts/agent6.txt
a=$(awk '{if ($8 >0) print "", $8}' /export/home/oraoem/scripts/agent6.txt)
b=$(grep "Agent is Running and Ready" /export/home/oraoem/scripts/agent.txt)
d=("Agent is Running and Ready")
if [ "$b" != "$d" ]
then
echo "OEM Agent is Not running ... .. " | mail -s "OEM Agent down on `hostname`" $DBALIST
elif [[ $a -gt 3 ]]
then
echo "Number of XML files pending upload : $a" | mail -s "OEM Agent upload problem on `hostname`" $DBALIST
fi
else
echo "OEM Agent down on `hostname`." | mail -s " OEM Agent down on `hostname`" $DBALIST
fi

##echo "OEM Agent is up and running on  `hostname`." | mail -s " OEM Agent up and running on `hostname`" $DBALIST

答案1

尝试用“睡眠”代替“等待”

相关内容