0

I have a shell script to monitor table stats and java apps. It works fine when I run manually. But if I put it in the crontab it will get stuck if I don't redirect it's output with export display command. Any idea why?

11
  • Do you mean export DISPLAY? That sounds like it's an X Windows application, so it needs to know the X server to put the window on. DISPLAY is normally set when you login to a GUI, and cron isn't in a GUI session.
    – Barmar
    Commented Apr 17, 2014 at 15:56
  • It would help if you posted the full command.
    – Barmar
    Commented Apr 17, 2014 at 15:56
  • heres the cron job */2 * * * * export DISPLAY=:1.0 && gnome-terminal -x /path/script.sh
    – ivcode
    Commented Apr 18, 2014 at 2:47
  • How do you expect gnome-terminal, whose whole purpose is to open a terminal emulator window on the screen, to work without setting DISPLAY?
    – Barmar
    Commented Apr 18, 2014 at 14:50
  • well I have opened display '1' and cronjob seems to work. But the problem is, if I add a cronjob for the same script without directing it to a display (ex: */2 * * * * /path/script.sh), the script will get stuck in middle of it's execution
    – ivcode
    Commented Apr 19, 2014 at 7:18

1 Answer 1

0

The command should be:

DISPLAY=:1.0 gnome-terminal -x /path/script.sh

Since gnome-terminal is an X application, it uses the DISPLAY environment variable to connect to the X server and display its windows. To set an environment variable just for the duration of a single command, put the variable assignment at the beginning of the command line.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .