linux定时任务crond export变量问题群友案例

2022-11-12 1471阅读

温馨提示:这篇文章已超过518天没有更新,请注意相关的内容是否还可用!

1)我写了一个重启resin的脚本,由于业务原因,需要定时在某一个时间重启下resin服务器,于是就在crontab里配置了如下内容:50 17 * * 1-5 root /usr/local/bin/resin_restart.sh其中crontab 重启服务器,resin_restart.sh内容如下:#!/bin/sh/usr/local/bin/xxresin_stop.sh/usr/local/bin/xxresin_start.sh

linux定时任务crond export变量问题群友案例
(图片来源网络,侵删)
linux定时任务crond export变量问题群友案例
(图片来源网络,侵删)

2)有问题的时刻到来了,服务器虽然定时起来了,但是却报了如下错误:Resin can't load com.sun.tools.javac.Main. Usually this means that the JDK tools.jar is missing from the classpath,possibly because of using a JRE instead of the JDK.

linux定时任务crond export变量问题群友案例

You can either add tools.jar to the classpath or change the compiler to an external one with or jikes.但是,明明已经在profile里配置了环境变量,为啥还找不到呢。折腾了需求没有搞定。

由于export变量问题导致:具体为,crontab执行shell时只能识别为数不多的系统环境变量,普通环境变量一般是无法识别的crontab 重启服务器,如果在编写的脚本中需要使用变量,最好使用export重新声明下该变量,以确保脚本正确执行。以后作为一个开发基本规范写上。

4)然后我在resin重启脚本里重新定义了下环境变量,脚本如下:#!/bin/sh#下面就是环境变量定义JAVA_HOME="/opt/jdk1.6.0_18"CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jarPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:/opt/nginx-0.7.61/sbin:/opt/jdk1.6.0_18/bin:/opt/resin-3.0.25/bin:$PATHexport JAVA_HOME PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC CLASSPATH/usr/local/bin/xxresin_stop.sh/usr/local/bin/xxresin_start.sh

linux定时任务crond export变量问题群友案例

VPS购买请点击我

文章版权声明:除非注明,否则均为主机测评原创文章,转载或复制请以超链接形式并注明出处。

目录[+]