Hello i am trying to open two shell scripts on reboot.

Crontab My crontab is the following

@reboot sh /home/pi/Desktop/autoStart.sh

autoStart.sh in this shell script is the following

cd /home/pi/Desktop
sudo xterm -e ./startNodeServer.sh &
sudo xterm -e ./startPythonScanner.sh

Error The error i get is

xterm: Xt error: Can't open display: %s
xterm: DISPLAY is not set

Thanks for the help

3 Answers 3


The answer is in the error message. DISPLAY is not set. Cron is not a part of your desktop environment, so it does not know where to display the xterm.

If you open an xterm normally, and ask echo $DISPLAY, it will tell you soemthing like


That is the display identifier where windows would be displayed. Unfortunately, you cannot just put


in your script because

  • there is a form of security that prevents opening windows on the display of another login (xauth)
  • your X server may not be running yet when the cronjob is executed.

The solution depends on what kind of window manager you are running. If default raspian, it would probably be something like:

  • auto-login pi (via raspi-config)
  • put @/home/pi/Desktop/autoStart.sh in /home/pi/.config/lxsession/LXDE-pi/autostart

You CAN NOT start GUI scripts with crontab - just boot to the GUI and use .config/lxpanel/LXDE-pi/autostart to start your scripts.

To run an application you simply add it on a line starting with a '@' character.

  • Well, not completely true. If you are logged-in in the GUI, do an xhost + and put * * * * * /usr/bin/xterm -display :0.0 -e sleep 5 in your crontab, you'll see that you can start GUI stuff from crontab. But xhost + is of course bad practice. Oct 26, 2019 at 11:09
  • @LjmDullart You are right, that the categorical "CAN NOT" is not correct. But in this special case: Can you be sure that the crontab @reboot is executed after the XServer has started. If not, there is no XServer that can display the xterm. And because @reboot is sometimes used to initialize e.g. special network drivers, I doubt that the X-Server is running when the script is performed. Your answer is helpful (uv), but the comment might confuse the OP. Oct 26, 2019 at 11:47

Starting programs and scripts are controlled by systemd with Unit files. With it you can define the needed environment to run the program. But because we know nothing about your scripts and what they are doing I can only suggest a general template to start a script with GUI. Create a new service with:

rpi ~$ sudo systemctl --force --full edit node-server.service

In the empty editor insert these statements, save them and quit the editor:

Description=Node Server

ExecStart=/usr/bin/xterm -c /home/pi/Desktop/startNodeServer.sh


Enable and start the new service with:

rpi ~$ sudo systemctl enable --now node-server.service

Check with:

rpi ~$ systemctl status node-server.service

Create and start just a second python-scanner.service for startPythonScanner.sh in the same way. Maybe you have to define Wants=node-server.service and After=node-server.service in its [Unit] section. If it doesn't work you have to look what additional environment settings are needed or you may elaborate your question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.