Scripts that execute jar programs are run regularly using crontab in centOS6

  • 2021-07-09 09:43:49
  • OfStack

1. Write a simple java program


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

Package the above program into centOS6

2. Write shell scripts


#!/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

Note here that the environment variable jar with java writes the absolute path address where the packet is located

3. Edit Timing File (crontab-e)

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

Summarize


Related articles: