crontab 定时任务报错 java: command not found

在原来服务器上写的定时任务,在任务转移之后定时任务不能成功执行,脚本没问题,用 sh 命令可以执行,但是目标地点没有数据,日志显示报错 :

From [email protected]  Wed Jun 26 16:11:01 2019
Return-Path: 
X-Original-To: root
Delivered-To: [email protected]
Received: by bd-bi-node06.localdomain (Postfix, from userid 0)
    id 8189420F7908; Wed, 26 Jun 2019 16:11:01 +0800 (CST)
From: "(Cron Daemon)" 
To: [email protected]
Subject: Cron  /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: 
X-Cron-Env: 
X-Cron-Env: 
X-Cron-Env: 
X-Cron-Env: 
X-Cron-Env: 
X-Cron-Env: 
X-Cron-Env: 
Message-Id: <[email protected]>
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

你可能感兴趣的:(crontab 定时任务报错 java: command not found)