Only my share

Java , Groovy and others

Running Groovy script from crontab in Linux

with 2 comments

I got a task to gather some log files into one single log file. What I was thinking about when I tried to implement this task using Groovy is my previous failure experiences to run it from crontab service in Linux.

But now, I have a good steps to solve this problem.

1. Assume that our Groovy script located at : /opt/btel/script/aldry/fnflog/fnfLogForDW.groovy
2. create a bash script to be run withing crontab service:

JAVA_HOME=your-java-home-directory
GROOVY_HOME=your-groovy-home-directory
export JAVA_HOME
export GROOVY_HOME

PATH=$JAVA_HOME/bin:$GROOVY_HOME/bin:$PATH:.
export PATH

cd /opt/btel/script/aldry/fnflog
groovy -classpath /opt/btel/script/aldry/fnflog //opt/btel/script/aldry/fnflog/fnfLogForDW.groovy

 3. Assume that we saved that bash script to the file : /opt/btel/script/aldry/fnflog/fnfLogForDW
4. type the following command from the console to install your script in the crontab service
                  shell> crontab -e
5.Put the following line, assume that this script will be run every 1:00 AM :
                   0 1 * * * /opt/btel/script/aldry/fnflog/fnfLogForDW
6. Restart crond service with the following command:
                   service crond restart
7. Enjoy :)

Written by adpjhype

January 2, 2009 at 9:15 am

Posted in Groovy

Tagged with

2 Responses

Subscribe to comments with RSS.

  1. Is there any way to run the Groovy script from the cron directly without having to create a companion shell script? I have !/usr/bin/env groovy at the top of my Groovy script, so I thought it would work, but it doesn’t.

    Ken Weiner

    January 29, 2009 at 11:10 pm

  2. you could probably use ‘java -jar groovy-1.x.x.jar -DGROOVY_HOME=…’ etc
    ‘groovy’ command is actually a wrapper around that command.

    vr

    March 30, 2009 at 5:25 am


Leave a Reply