0
votes

I have a Grails app, but I need to execute some script by Cron. This script must have access to database by Gorm. It is possible to make grails create-script cron-script. But how to deply it into war or jar file?

2

2 Answers

2
votes

The most common way to execute scripts at regular intervals in a Grails app is via the Quartz plugin. There's no easy way to have access to GORM from a cron job.

0
votes

If you have the Console Plugin installed, it can be called using curl from a shell script executed by cron. Do something like this:

#/bin/bash

import groovy.sql.Sql
def dataSource = ctx.dataSource
def sql = new Sql(dataSource)

curl -i -H "Content-type: application/x-www-form-urlencoded" -c /tmp/cookies.txt -X POST www.yoursite.com/j_spring_security_check -d "[email protected]&j_password=verysecretpassword"

curl -i -b /tmp/cookies.txt -d 'code=
  sql.executeUpdate("insert into yourtable (test) values (42)")
' www.yoursite.com/console/execute