zoukankan      html  css  js  c++  java
  • crontab无法调用java的问题解决

    本来想将写的代码挂在crontab下运行,谁知道无法运行,没有任何输出,试着用ls -al >> 1.log试了一下,确定crontab是正常运行的。

    从网站上找了下问题,原因出在crontab启动的程序并不会加载环境变量,因此像“java”这种命令是无法启动的。 
    解决方案就是讲java换做具体的java路径。
    步骤如下:
    1. 运行命令crontab -e加入要运行的命令,并配置其运行频次
     
    30 01 * * * /opt/changedig/app/module/rcproject/rcproject.sh
    2. 修改启动脚本,将java路径换做绝对路径
     
    #!/bin/sh
    WORK_DIR="/opt/changedig/app/module/rcproject"
    MYNAME="rcproject"
    pidfile=.$MYNAME.pid
    if test -f $WORK_DIR/$pidfile
    then
    # See if a process is running with that process id
    pid=`cat $WORK_DIR/$pidfile`
    if test -n "$pid"
    then
    ps -ef|grep $MYNAME|grep -v grep|awk '{print $2}'|grep $pid > /dev/null
    if test $? -eq 0
    then
    # The process is running !
    printf "The process is running !
    "
    exit 3
    else
    # Try the ps listing again as it is not always reliable
    ps -ef|grep $MYNAME|grep -v grep|awk '{print $2}'|grep $pid > /dev/null
    if test $? -eq 0
    then
    # The process is running !
    printf "The process is running !
    "
    exit 3
    fi
    fi
    fi
    fi
    echo $$>$WORK_DIR/$pidfile
    # Check process is existence
    if [ ! -f $WORK_DIR/rcproject-0.0.1.jar ] ; then
    printf "Error: Can not find the file $WORK_DIR/rcproject-*.jar
    "
    return 2
    fi
    /usr/local/java/jdk1.7.0_45/bin/java -jar $WORK_DIR/rcproject-0.0.1.jar
    如此即可
  • 相关阅读:
    php yield
    原来 php 中的 json_encode() 只支持utf-8.不支持gbk啊
    mongodb 二进制安装
    Centos 6.3 安装教程
    php 测试 程序执行时间,内存使用情况
    workerman vmstat服务器状态监控服务
    php大量数据 10M数据从查询到下载 【内存溢出,查询过慢】解决方案
    PHP_EOL DIRECTORY_SEPARATOR
    利用curl 模拟多线程
    Laravel 输出最后一条sql
  • 原文地址:https://www.cnblogs.com/jiyuqi/p/4981090.html
Copyright © 2011-2022 走看看