Execute wolfram as cron job

Hi,

I made Mathematica script that could be executed on RPI by:

$ wolfram -script ./script_name.m

and it does what I wish. But if I try to execute it from cron job:

27 * * * * sudo wolfram -noprompt -script /home/user/path/script_name.m > cron_log.txt

with or with out sudo and -noprompt, all I get is entry into cron_log.txt:

Developer`LaunchFrontEnd::nxsrv: An x server is required for that operation.

Rasterize::nofe: A front end is not available; Rasterize requires a front end.
$Failed

Developer`LaunchFrontEnd::nxsrv: An x server is required for that operation.
Rasterize::nofe: A front end is not available; Rasterize requires a front end.
$Failed

Script is txt file and uses Import, DateListPlot, and Export command to save plot as PNG.

Any idea why and how…

I’m assuming your script uses Rasterize indirectly through the Export command. Do you still get the error if you don’t Export?

=============================Updated=========================
If Rasterize is essential in your application, you may need to include this line in the code. Sometimes you also have to include the Java graphics package in the kernel command so you can export graphics object like what can be done with FrontEnd (by default, the graphics is exported to $HomeDirectory ):

<<JavaGraphics`
Export["test.jpg",Rasterize[1]]

This link shows an application of the lines above.

@ BoB
No Export[] no error, but no useful result also.

@ Shenghui Yang
Could you write the code?
Something like:

Needs["JLink`"]
UseFrontEnd[Export[...]]

or not?