I run mathematica on a remote server and run it in batch mode using /math -noprompt -script 'scriptname.m' &

Now, I use ssh -X to connect to the server. The server is linux based and my computer is a mac. I use x11 forwarding.

I would like to generate PDFs in the above mentioned 'script.m'. In my code, how should I incorporate UseFrontEnd? should I invoke it first using ConnectToFrontEnd[] ? Should I use UseFrontEnd[Export["blah.pdf",fig]] or is it a one time thing?
Also, when using the UseFrontEnd command, is it required that I do ssh -X/Y or is it sufficient if I do ssh?

The UFE = UsingFrontEnd line is to make the input lines shorter. Of course you could write plot = UsingFrontEnd @ Plot[x^2,{x,-2,2}].

After inspecting the output of monitorlm (Mathematica network license manager) I think that the first invocation of UsingFrontEnd starts a SubMathematica process and the same process is used in subsequent UsingFrontEnd commands. The SubMathematica process is terminated when the interactive MathKernel session is closed.

I'm sure things are very similar when using a .m script.

edit I am using Mathematica 7.0.1.0 installed on Ubuntu 11.10 end edit

edit 2 After OP's comment I chcecked that to Plot[] and Export[] you don't need UsingFrontEnd. So the following works fine:

this looks promising. I'll try. So you say I have to say UsingFrontEnd every time before I invoke some kind of plotting command or export graphics? Is there a way to just turn the switch on at the beginning of the script and turn it off at the end?
–
preetiNov 21 '12 at 19:35

welll it seems you don't need the UsingFrontEnd command to plot = Plot[x^2,{x,-2,2}] and Export["/home/username/output.jpg",plot]. The reference says that UsingFrontEnd is neccesary for NotebookWrite[] and similar functions (I have used it to NotebookPrint[] some time ago).
–
au700Nov 21 '12 at 19:44

Mathematica is a registered trademark of Wolfram Research, Inc. While the mark is used herein with the limited permission of Wolfram Research, Stack Exchange and this site disclaim all affiliation therewith.