Centos

CentOs 7 CronTab 設置 JAVA_HOME

  • February 28, 2016

對於root使用者,我為 crontab 配置了 JAVA_HOME 變數,如下所示:

[root@localhost ~]# vim /etc/crontab
_______
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/opt/jdk1.8.0_71/bin
MAILTO=root
JAVA_HOME=/opt/jdk1.8.0_71
_______

我定義了一個由另一個使用者執行的 cronjob,tomcat如下所示:

[tomcat@localhost ~]$ crontab -e
_______
30 10 * * * /opt/tomcat/bin/shutdown.sh >> /opt/tomcat/logs/cron_restart.log 2>&1
32 10 * * * /opt/tomcat/bin/startup.sh >> /opt/tomcat/logs/cron_restart.log 2>&1
_______

作業執行,但我的日誌顯示以下內容:

[tomcat@localhost ~]$ vim /opt/tomcat/logs/cron_restart.log
______
Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variable is needed to run this program
Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variable is needed to run this program
______

**1.) 為什麼 crontab 沒有選擇 JAVA_HOME?

2.) 有哪些可能告訴 crontab JAVA_HOME 在哪裡?**

我的方法是基於此頁面的 CentOs-Docs: https ://www.centos.org/docs/5/html/5.2/Deployment_Guide/s2-autotasks-cron-configuring.html

3.)我是否有可能誤讀了文件?

我是這樣工作的:

在文件中插入以下行/opt/tomcat/bin/setenv.sh

export JAVA_HOME="/opt/jdk1.8.0_71"

引用自:https://unix.stackexchange.com/questions/264988