当前位置: 代码迷 >> 综合 >> linu crontab定时任务大坑:ps aux | grep *** 与文件名冲突
  详细解决方案

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

热度:92   发布时间:2023-10-17 03:31:55.0

我的 .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_processif [[ -n $hive_process ]]; thenecho "${now_time}  process exist."elseecho "${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

  相关解决方案