![通过 cron 调用 shell 脚本时,wait 命令被忽略或不起作用](https://linux22.com/image/1501222/%E9%80%9A%E8%BF%87%20cron%20%E8%B0%83%E7%94%A8%20shell%20%E8%84%9A%E6%9C%AC%E6%97%B6%EF%BC%8Cwait%20%E5%91%BD%E4%BB%A4%E8%A2%AB%E5%BF%BD%E7%95%A5%E6%88%96%E4%B8%8D%E8%B5%B7%E4%BD%9C%E7%94%A8.png)
我们需要监控 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
尝试用“睡眠”代替“等待”