当前位置:主页 > 服务器 > Linux >

centOS6中使用crontab定时运行执行jar程序的脚本

时间:2021-01-23 10:17:26 | 栏目:Linux | 点击:

1、编写一个简单的java程序

public class testshell {
  public static void main(String[] args) {
    int count = 0;
    for (String arg : args) {
      System.out.println("第" + (++count) + "个参数:" + arg);
    }
  }
}

将上述程序打包放到centOS6中

2、编写shell脚本

#!/bin/bash
export JAVA_HOME=/usr/local/jdk1.8.0_91
export PATH=$JAVA_HOME/bin:$PATH
A=`date`
java -cp /root/Desktop/testshell.jar com.testshell "$A" >>/root/Desktop/c.txt

此处注意配java的环境变量 jar包所在位置写绝对路径地址

3、编辑定时文件(crontab -e)

*/1 * * * * /root/Desktop/b.sh

总结

您可能感兴趣的文章:

相关文章