在原来服务器上写的定时任务,在任务转移之后定时任务不能成功执行,脚本没问题,用 sh 命令可以执行,但是目标地点没有数据,日志显示报错 :
From root@bd-bi-node06.localdomain Wed Jun 26 16:11:01 2019
Return-Path: <root@bd-bi-node06.localdomain>
X-Original-To: root
Delivered-To: root@bd-bi-node06.localdomain
Received: by bd-bi-node06.localdomain (Postfix, from userid 0)
id 8189420F7908; Wed, 26 Jun 2019 16:11:01 +0800 (CST)
From: "(Cron Daemon)" <root@bd-bi-node06.localdomain>
To: root@bd-bi-node06.localdomain
Subject: Cron <root@bd-bi-node06> /home/data/datax/interfaces/t_interfaces_all.sh >/home/data/datax/interfaces/file.txt
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated
Precedence: bulk
X-Cron-Env: <XDG_SESSION_ID=3059>
X-Cron-Env: <XDG_RUNTIME_DIR=/run/user/0>
X-Cron-Env: <LANG=en_US.UTF-8>
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
X-Cron-Env: <USER=root>
Message-Id: <20190626081101.8189420F7908@bd-bi-node06.localdomain>
Date: Wed, 26 Jun 2019 16:11:01 +0800 (CST)
/bin/sh: java: command not found
/bin/sh: java: command not found
/bin/sh: java: command not found
发现是因为缺少环境变量,需要在 crontab 命令中指定环境变量位置,改了命令就可以了。
0 2 * * * . /etc/profile;sh /home/data/datax/interfaces/t_interfaces_all.sh