Search code examples
grailsgroovycrongroovy-console

Cron-like application of groovy script with console plugin environment?


We have an application that we would like to run a script on just like we do in the console window with access to the applications libraries and context, but we need to run it periodically like a cron job.

While the permanent answer is obviously a Quartz job, we need to the do this before we are able to patch the application.

Is there something available that gives us the same environment as the console-plugin but can be run via command-line or without a UI?


Solution

  • you can run a console script like the web interface does but just with a curl like this:

    curl -F 'code=
    class A {
      def name
    }
    
    def foo = new A(name: "bar")
    println foo.name
    ' localhost:8080/console/execute
    

    You'll get the response as the console would print below.