版权声明:作者-傲娇天子 博文主页地址:https://blog.csdn.net/qq_41116956 欢迎转载,转载请在文章页面明显位置给出原文链接,谢谢 https://blog.csdn.net/qq_41116956/article/details/83006975
crontab 设置定时执行任务不执行:
1:服务crond正常
hadoop@suitang02:~$ service cron status
cron start/running, process 984
2:crond服务正常执行
[root@localhost ~]# tail -1 /var/spool/cron/root
*/1 * * * * echo 123 > /root/1.txt
[root@localhost ~]# ls
1 nginx-1.12.2 tar 模板 图片 下载 桌面
anaconda-ks.cfg nginx-1.12.2.tar.gz 公共 视频 文档 音乐
[root@localhost ~]# ls
1 anaconda-ks.cfg nginx-1.12.2.tar.gz 公共 视频 文档 音乐
1.txt nginx-1.12.2 tar 模板 图片 下载 桌面
3:单独执行成功
root@stubuntu:/home/hadoop# tail /var/spool/cron/crontabs/hadoop
...
*/5 * * * * /bin/bash /home/hadoop/Maxwell_restart.sh
root@stubuntu:/home/hadoop# pwd
/home/hadoop
root@stubuntu:/home/hadoop# ./Maxwell_restart.sh
在满足所有情况下.sh文件依然不执行:
小博主跳坑提示:crontab不会调用jdk变量
而.sh脚本中会使用到和java相关的程序(将.sh脚本中的执行命令重定向给一个空文本,由crontab执行后空文本中会有提示:...exec:java:not found)
解决方法:
在.sh脚本中引入环境变量
. /etc/profile
. ~/.bash_profile
crontab执行成功!
完!