linux crontab 无法执行shell脚本解决方法
来源:互联网 发布:互联网金融 加班 知乎 编辑:程序博客网 时间:2024/05/01 09:05
crontab 创建了一定时任务,每分钟去执行一个shell脚本
*/1 * * * * sh /home/test/start.sh
==============================
start.sh :
#!/bin/bash
cd /home/test
sh kill.sh
java -jar test.jar
==============================
kill.sh :
#!/bin/bash
pid=`ps -ef | grep java | awk '{if($0 ~/test.jar/) print $2}'`
if [ "$pid" != "" ];then
kill -9 $pid
echo "test.jar killed: pid $pid"
else
echo "No test.jar running."
fi
==============================
发现test.jar一直没被执行,但是直接执行shell脚本:sh start.sh 是可以让test.jar跑起来的。
一开始怀疑crontab没生效,但是用tail -f /var/log/cron 看了crontab的日志之后,发现crontab的确是在运行的
于是就把crontab的运行日志打印到 /home/test/log, 在crontab -e 中修改:
*/1 * * * * sh /home/test/start.sh 2>>/home/test/log
等到下一次crontab执行之后,打开日志查看。信息如下:
/home/test/start.sh: line 4: java: command not found
那么基本猜到是path的问题了
于是就把java相关的环境变量引进来,通过source命令引入环境变量:source /etc/profile
修改start.sh,增加一行。
start.sh :
#!/bin/bash
source /etc/profile
cd /home/test
sh kill.sh
java -jar test.jar
等下下一次crontab执行时,就正确了!
- linux crontab 无法执行shell脚本解决方法
- LINUX定时执行SHELL脚本实现DB2数据库操作,crontab无法正常识别执行
- linux 定时执行shell脚本 crontab
- Crontab 让linux定时执行shell脚本
- Linux利用crontab定时执行shell脚本
- 使用crontab,让linux定时执行shell脚本【crontab -e】
- crontab执行任务调用shell脚本,相对路径无法找到
- crontab 定时执行shell脚本
- crontab 定时执行shell脚本
- crontab 定时执行shell脚本
- 使用crontab,让linux定时执行shell脚本
- linux系统crontab执行jar包的shell脚本
- 使用crontab,让linux定时执行shell脚本
- 通过linux的crontab实现定时执行shell脚本功能
- 使用crontab,让linux定时执行shell脚本
- 使用crontab,让linux定时执行shell脚本
- Linux下无法执行shell脚本问题
- Notepad++编写的shell脚本在linux下无法执行的解决方法
- WIN7 下清楚SVN用户名和密码
- 8 个 git 的小技巧
- 抓取表中满足条件的数据及图片
- 第十八题(文件)
- 冒泡排序
- linux crontab 无法执行shell脚本解决方法
- IOS 公司开发者账号申请详细教程-13810208661
- execle表快速移动表格到另一个execle表
- MetaQ-1
- springmvc form表单标签使用
- ActiveMQ消息确认的问题
- Leetcode Distinct Subsequences Java
- 关于在openstack的环境变量.bashrc自定自己简化命令
- 第十七题(java的标签)