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?
0
votes
2 Answers
2
votes
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