DataX踩坑2 | 定时任务crontab不执行或报错:/bin/sh: java: command not found

前面两天写了一个DataX的增量同步脚本,今天检查了一下发现定时任务没有执行成功,数据并没有同步。以下为排查问题和解决方法。


一、定时任务crontab不执行

脚本(测试用的可以设为每分钟一次:*/1 * * * *):

0 5 * * * /opt/datax/bin/incrSyncTask.sh >/dev/null 2>&1
1.查看crontab日志,看是否成功执行了脚本:
tail -f /var/log/cron

在这里插入图片描述

报错:

Oct 28 09:32:10 izwz9j58zzz42e5r70ct5oz crontab[18564]: (root) REPLACE (root)
Oct 28 09:32:10 izwz9j58zzz42e5r70ct5oz crontab[18564]: (root) END EDIT (root)
Oct 28 09:33:01 izwz9j58zzz42e5r70ct5oz crond[513]: (root) RELOAD (/var/spool/cron/root)
Oct 28 09:33:01 izwz9j58zzz42e5r70ct5oz CROND[19639]: (root) CMD (/opt/datax/bin/incrSyncTask_prod.sh)
Oct 28 09:33:01 izwz9j58zzz42e5r70ct5oz CROND[19638]: (root) MAIL (mailed 191 bytes of output but got status 0x004b#012)

这里表示发送邮件到mail邮箱失败,要重新配置,查看第三步

2.查看mail邮箱日志
tail -f /var/log/maillog

在这里插入图片描述
还是报错:
sendmail: fatal: parameter inet_interfaces: no local interface found for ::1


3.解决方法

修改/etc/postfix/main.cf文件中的inet_interfaces参数inet_interfaces = all即可

vim /etc/postfix/main.cf

下面是原来默认的值:
在这里插入图片描述

修改保存后,就可以看到定时任务不会报错了

二、crontab定时任务执行Shell脚本报错:/bin/sh: java: command not found

报错:/bin/sh: java: command not found
解决方法:

在shell脚本中加入下面的参数即可:

. /etc/profile

在这里插入图片描述

加入后定时任务就可以正常的运行shell脚本了。

相关文章


猜你喜欢

转载自blog.csdn.net/qq_25112523/article/details/109333611