bash脚本等待MQTT服务启动后再启动程序

需要程序能在系统启动时自动启动,而有时候系统刚启动,某些必须的服务还没起来,会导致程序启动失败,所以需要先判断服务有没有起来,本例中需要MQTT

#!/bin/bash
xdotool mousemove  0 0  #隐藏鼠标
unclutter -idle 3 &

source /etc/profile   

if [ -e  /root/startup.log ]      #计数看MQTT 服务什么时候能起来,等待秒数保存在startup.log
then
        rm  /root/startup.log
fi
echo `date +'%Y-%m-%d %H:%M:%S'` :  Startup.....>> /root/startup.log
while [ `sudo service mosquitto status |grep -c "running"` != 1 ]   #计数看MQTT 服务是否起来
do
        echo `date +'%Y-%m-%d %H:%M:%S'` : mqtt not ready... >> /root/startup.log
        sleep 1
done
echo  `date +'%Y-%m-%d %H:%M:%S'` : mqtt OK !>>  /root/startup.log
numlockx on 
cd /home/myworkdir/
./mypro&

————————————

需要500关注,拜托点个关注,必定回关,谢谢!

你可能感兴趣的:(bash脚本编程技能点积累,速查备忘,bash,bash脚本程序编写技能积累)