0

I'm using cron scheduler (quartz) and for some reasons (server down...) sometimes a task don't trigger. I wan't to check if task ran or not. My idea was to do that based on cron: I get previous fire date (for example: 0 7 11 4 * ? = At 11:07:00am, on the 4th day, every month I should have 2018/07/04) and I compare it to the latest task's date (got it in db): if it's different then I know task didn't run.

My problem is getting previous fire date. I tried suggestions here: Finding Last Fired time using a Cron Expression in Java as trigger.getPreviousFireTime();But still not working... No problem getting next fire time but impossible to get previous fire time (having null or wrong date).

Any idea ?

Emeric
  • 6,315
  • 2
  • 41
  • 54

1 Answers1

1

I think what you're looking for is the syslog. Depending on which *nix you're using, you can run:

grep cron (location)

and get the data you want. From there you can process it however you like.

Ubuntu Cron Log Location Linky

I'd personally use this SO question to get the output of this call from Java:

Call a command from Java

And as a final note, using:

grep cron /var/log/syslog | tail -1

will get you just the last line. On my Linux-based server, the line looks like this:

Jul 10 12:17:01 ---------- junk removed -------------------

I would take the first 15 characters of that and parse it.

Dylan Brams
  • 2,089
  • 1
  • 19
  • 36