shell脚本放到crontab里定时执行
来源:互联网 发布:c语言一维数组最大长度 编辑:程序博客网 时间:2024/05/21 18:17
需求需要定时检查zookeeper进程和mq进程,当进程不存在时去需要自动启动,把检查进程的脚本写好后,添加到crontab中 设置定时多久执行。
检测zookeeper进程脚本 check_zk.sh
#!/bin/sh#echo `date`source /etc/profilePID=`ps aux | grep QuorumPeerMain | grep -v "grep" |wc -l`#pid=`ps aux | grep QuorumPeerMain | grep -v "grep"`echo $PIDwhile [ $PID -eq 0 ]; do echo `date` echo '开始启动zk脚本' /home/ekanet/esb/zookeeper-3.4.6/bin/zkServer.sh start & sleep 1 exit 0done
检测mq进程脚本 check_mq.sh
#!/bin/sh#echo `date`source /etc/profilePID=`ps aux | grep activemq.jar | grep -v "grep" |wc -l`#pid=`ps aux | grep activemq.jar | grep -v "grep"`echo $PIDwhile [ $PID -eq 0 ]; do echo `date` echo '开始启动mq脚本' /home/ekanet/esb/apache-activemq-5.13.4/bin/activemq start & sleep 1 exit 0done
编辑crontab 使用命令 crontab -e
#每隔1分钟检测一次*/1 * * * * /home/ekanet/esb/scripts/check_zk.sh >> /home/ekanet/esb/scripts/zklog.log*/1 * * * * /home/ekanet/esb/scripts/check_mq.sh >> /home/ekanet/esb/scripts/mqlog.log
在实际使用中碰到直接执行脚本check_zk.sh能运行,但是放置到crontab中执行时并不能把zk服务启动起来。解决方法
有些shell脚本正常执行没问题,但放到crontab里就执行不成功,原因是因为crontab执行脚本的时候不会读取用户的环境变量等配置
解决方法:
1.在shell前面export下$PATH
- 1
2.或者source下/etc/profile
阅读全文
0 0
- shell脚本放到crontab里定时执行
- shell脚本放到crontab里就执行不成功的问题
- crontab 定时执行shell脚本
- crontab 定时执行shell脚本
- crontab 定时执行shell脚本
- linux 定时执行shell脚本 crontab
- Crontab 让linux定时执行shell脚本
- 使用crontab定时执行shell脚本
- Linux利用crontab定时执行shell脚本
- 使用crontab,让linux定时执行shell脚本【crontab -e】
- Linux手动执行脚本可以,但是放到定时任务 crontab 中不执行
- 使用crontab,让linux定时执行shell脚本
- 使用crontab,让linux定时执行shell脚本
- 通过linux的crontab实现定时执行shell脚本功能
- 使用crontab,让linux定时执行shell脚本
- 使用crontab,让linux定时执行shell脚本
- crontab 定时执行python脚本
- crontab 定时执行python脚本
- 引用的知识(二)
- Hibernate四种状态
- okhttp下载
- CCleaner恶意代码分析预警
- 查找论文的有用链接
- shell脚本放到crontab里定时执行
- Linux系统调用的实现机制分析
- setContentView源码解析
- PageHelper插件的使用
- 菲波那切数列 :矩阵加速递推 矩阵快速幂
- C++,vector模板类的问题? std::vector<PointT, Eigen::aligned_allocator<PointT> > points;
- UML类图常用符号
- Android ListView异步加载网络图片出现位置错乱闪烁及优化ListView的加载
- C++面试题(十一).西山居