linu crontab定时任务大坑:ps aux | grep *** 与文件名冲突

我的 .sh文件名为 hiveserver2_monitor.sh

脚本内容


source /etc/profile
now_time=$(date +"%Y-%m-%d %H:%M:%S")

function checkProcess()
{
    hive_process=$(ps aux | grep hiveserver2 | grep -v grep |grep -v 'hiveserver2_monitor\.sh')
    echo $hive_process
    if [[ -n $hive_process ]]; then
       echo "${now_time}  process exist."
    else
        echo "${now_time} hive2 is restart"
       # echo "${now_time} hiveserver2 restart" > ${ERR_FILE}
        nohup /usr/local/bigdata/apache-hive-2.3.2-bin/bin/hive --service hiveserver2 >> /home/admin/css/logs/hiveserver2.log 2>&1 &
   fi
}

checkProcess

crontab定时任务

#监控hiveserver2自动拉起服务

*/1 * * * * /bin/sh -c /home/admin/css/script/test_hive.sh >> /home/admin/css/logs/crontab_monitor_hive3.log

重点来了,当我把相应进程kill掉以后,crontab的输出日志为

admin 22993 0.0 0.0 113128 1200 ? Ss 20:13 0:00 /bin/sh -c /home/admin/css/script/hiveserver2_monitor.sh >> /home/admin/css/logs/crontab_monitor_hive3.log admin 22995 0.0 0.0 113132 1216 ? S 20:13 0:00 /bin/sh -c /home/admin/css/script/hiveserver2_monitor.sh >> /home/admin/css/logs/crontab_monitor_hive3.log admin 23041 0.0 0.0 113132 608 ? S 20:13 0:00 /bin/sh -c /home/admin/css/script/hiveserver2_monitor.sh >> /home/admin/css/logs/crontab_monitor_hive3.log
2019-06-17 20:13:02  process exist.

还是会显示进程存在,一直走不到下面的循环

为啥我的sh文件里没有这些日志,但crontab的重定向里会有这些日志呢,找了很久很久,最后找工作运维经理,一分钟解决

因为

我的脚本文件名 hiveserver2_monitor.sh 与 ps aux | grep hiveserver2 | grep -v grep中的hiveserver2冲突了,对,冲突了!!!!!

 

这是小白才会犯的错么!!!!

 

另外,定时任务起不来,记得查看下crontab状态   service crond status 是否为active

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值