时间: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
总结