shell腳本配置引用環境變量

    最近配置腳本定時用ks3服務存儲日誌文件,ks3執行須要配置java變量,直接shell執行都沒有問題,可是配置crontab,則不能正常執行。定時任務報錯日誌以下:java

Subject: Cron <root@vm192-168-5-15> sh /vnum/monitorshell/synLogToKs3.sh
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated
Precedence: bulk
X-Cron-Env: <XDG_SESSION_ID=39003>
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: <20190302192001.C10CA615A4@vm192-168-5-15.ksc.com>
Date: Sun,  3 Mar 2019 03:20:01 +0800 (CST)shell

which: no java in (/usr/bin:/bin)
Error: JAVA_HOME is not defined correctly.
  We cannot execute bash

From root@vm192-168-5-15.ksc.com  Sun Mar  3 03:20:07 2019
Return-Path: <root@vm192-168-5-15.ksc.com>測試

       原來是在定時任務中執行,腳本沒法引用到java環境。查看查看環境變量:echo $PATH日誌

[root@vm192-168-5-15 monitorshell]# echo $PATH
/usr/lib64/qt-3.3/bin:/var/local/jdk1.8.0_172/bin:/var/local/jdk1.8.0_172/jre/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin
[root@vm192-168-5-15 monitorshell]#

        在腳本/vnum/monitorshell/synLogToKs3.sh  起始配置引用環境變量:code

export PATH=$PATH:/var/local/jdk1.8.0_172/bin:/var/local/jdk1.8.0_172/jre/bin

    測試定時執行,問題解決。crontab

相關文章
相關標籤/搜索