首页 > 系统服务 > 详细

shell中if条件语句结尾fi前面如果有&可以没有;

时间:2020-06-30 13:29:57      阅读:70      评论:0      收藏:0      [点我收藏+]

场景

crontab中需要新增一个自愈操作,如果进程不存在则重启进程。类似下面:

*/5 * * * * if [ -z $(ps -ef | grep filebeat | grep -v grep) ];then nohup /app/filebeat-7.7.0/filebeat -e -c /app/filebeat-7.7.0/kafka_log.yml &> /dev/null &;fi

但会报错:

-bash: syntax error near unexpected token `;‘

解决方案

如果fi前面有&则可以不使用;进行隔离

*/5 * * * * if [ -z $(ps -ef | grep filebeat | grep -v grep) ];then nohup /app/filebeat-7.7.0/filebeat -e -c /app/filebeat-7.7.0/kafka_log.yml &> /dev/null & fi

shell中if条件语句结尾fi前面如果有&可以没有;

原文:https://www.cnblogs.com/Peter2014/p/13213068.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!