Question

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?

Was it helpful?

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.

OTHER TIPS

With regard to @mwaisgold 's solution above, I made a couple of quick additions that helped. I added a little bit more to the script to handle authentication, plus the -F flag for curl caused an ambiguous method overloading error with the GroovyShell's evaluate method, so I addressed that by using the -d instead:

#/bin/bash

curl -i -H "Content-type: application/x-www-form-urlencoded" -c cookies.txt -X POST localhost:8080/myapp/j_spring_security_check -d "j_username=admin&j_password=admin"

curl -i -b cookies.txt -d 'code=
int iterations = 0

while (iterations < 10) {
    log.error "********** Console Cron Test ${iterations++} ***********"        
}
log.error "********** Console Cron Test Complete ***********"

' localhost:8080/myapp/console/execute
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top