Disable mail from cron job

Most of the scripts I write include an email that includes status and timing of each command. When these are run via cron, I get a second email from the cronjob. In order to stop this just add this to the top of the cronjob file:


This will stop cron from sending out email and allows for turning back on when you need to debug.

Dynamic Dates For JasperServer

 Adding download for jrxml and jar file. 

Here is what the report should look like:

Clone bitbucket repo to get code:

Https: git clone https://brooneyx@bitbucket.org/brooneyx/js-dynamic-dates.git
SSh: git clone git@bitbucket.org:brooneyx/js-dynamic-dates.git


Many of the reports I design require a predefined set of dates for the user to choose. In addition I also like to allow the user to pick any start and end date they would like. The ability to choose a set of dates is especially important when we want to schedule reports, a static start and end date do not cut in this case. Out of the box, JasperServer does not have this functionality and I have been through several revisions on the way to my current implementation of  this feature.

First you need to come up with the list of dates that you would like to provide to the user. In my case I use the following:

When the user chooses “User Defined” we then use the following to allow for user settable start and end dates.

Setting up these input selectors is the easy part, the real work comes in the back-end code that interprets the choices and sets the appropriate start and end dates for the chosen time slice. In my case I decided to use Java to create a class that will return a date given a string that corresponds to the users pick list displayed above.

The prototypes for the functions are:

The Date parameter in the second set is there for the case when the user chooses “User Defined”, in this case I send in the date that they picked in order to have a single call to cover all choices.

The next step is to implement the  java code to calculate the dates from the user picks. Here is a snippet of the getStartDate and getEndDate methods for “Previous Month”:

Okay so now we know how to calculate a date given a string representation of that time slice. How do we integrate this into a JasperReport ? This is the real challenge that is needed to make it work.

First we need to create a set of parameters in the jrxml file that help us calculate and store the dates.

  • PickDate – (String) This will be filled in with the date choice (“Yesterday”, This Week”, etc).
  • StartDate – (Date) This is the users set start date (“User Defined”)
  • EndDate-  (Date) This is the users set end date  (“User Defined”)
  • StartDateChoice – (String) This is where we call the getStartDate method.
  • EndDateChoice – (String) This is where we call the getEndDate method.

For StartDateChoice we will set the “Default Value Expression” to: com.reptics.dateutils.DateByString.getStartDate($P{DateChoice},$P{StartDate})

We do something similar with EndDateChoice and then we need to use $P(EndDateChoice} in the query when looking for a date. This replaces strings like “This Year” with the date we calculated from the Java code.

To make this all work you need to define the correct input selectors in JasperServer for DateChoice, StartDate and EndDate.


Testing Reports

I use a single instance of JasperReportsServer Enterprise, this means that I use the same host for testing as well as production.  I ran into a problem where I was making some minor changes and it broke a set of reports, the bad part is I didn’t know they were broken till my users started to send me emails. With a larger set of reports on the horizon, I needed to come up with a plan to test the currently installed reports so I catch problems before any client does.

The plan I put into place seems to work fine for my situation, so I thought I would share what I did.

  • Create a servlet (it could be a script)  that allows me to run a report and return the data in csv format.
  • Run the report and export the data to a file in csv format. Save to a directory  call “expected”.
  • Create a Junit test that calls the the servlet and dumps the data to a file. Then open the file in the “expected” directory and diff them.

I did this with each test and on error I email myself the results.


Here is how I setup my eclipse project.