当前位置: 移动技术网 > 网络运营>服务器>Linux > centOS6中使用crontab定时运行执行jar程序的脚本

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

2020年03月09日  | 移动技术网网络运营  | 我要评论
1、编写一个简单的java程序 public class testshell { public static void main(string[] args) {

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

总结

以上所述是小编给大家介绍的centos6中使用crontab定时运行执行jar程序的脚本,希望对大家有所帮助

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网