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

素颜马尾好姑娘i 2022-11-20 09:53 768阅读 0赞

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


一、定时任务crontab不执行

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

  1. 0 5 * * * /opt/datax/bin/incrSyncTask.sh >/dev/null 2>&1
1.查看crontab日志,看是否成功执行了脚本:
  1. 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邮箱日志
  1. 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即可

  1. vim /etc/postfix/main.cf

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

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

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

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

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

  1. . /etc/profile

在这里插入图片描述

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

相关文章

  • DataX | 在Liunx上安装和使用.
  • DataX | MySQL多表全量同步和多表定时增量同步.
  • DataX踩坑1 | 连接数据库失败. 请检查您的 账号、密码、数据库名称、IP、Port.
  • Shell 脚本参数传递时有 \r 换行符问题.

发表评论

表情:
评论列表 (有 0 条评论,768人围观)

还没有评论,来说两句吧...

相关阅读