Cron work for Java programs
I'm using a java program that sends emails after some file transfers I am using eclipse to write program code How to set up a cron job to execute this Java program at a specific time I also have various jar files in the project Please suggest
Solution
R0ast3d has a quick and clear answer – I really need to do more searches to complete each step, so I'll explain his steps in detail:
>Write a shell script to call your Java program with the necessary parameters Example:
!/bin/bash echo "Running script." cd ~/your/classpath/to/java java -classpath .:somejar.jar path/to/your/Program
Use a colon (:) instead of a semicolon (;) Separate the necessary class paths. The path of your program should start with your package (find it at the top of the Java program) > make sure that the classpath parameter points to the jar you need You can check the import statement in a java program to ensure that all necessary Classpaths are specified You must run this script from the Java directory, and you can use a single period (.) As the first classpath parameter. > Ensure that the shell script has the necessary UNIX permissions
Run from the terminal: sudo Chmod ### yourscript sh
Where ### is the number indicating the correct permission set by the system. > Schedule the script to be called by setting the cron job
Run from terminal: crontab - e
This will open your crontab editor You can add jobs in the following ways:
* / 5 * * * * bash /home/scripts/yourScript. sh
Replace the path of the script with the correct location of the script This job is set to run every 5 minutes For more information about crontab, see http://www.adminschoice.com/crontab-quick-reference/.
I hope this can help others!