This question already has an answer here:

I have Debian stretch with systemd running (installed by default). I want to start a 2 lines bash script at boot via cron.

echo something > file.txt 

xfce4-terminal  [...] --command="watch [....]" 2>&1 & 

the script works fine when launched manually: A window is opened and a 'watch' command is launched. I use use the first line to check if it's launched at boot (like a kind of stamp).

I have tried with root user and non root. I edited cron with crontab -e and vi (export VISUAL="vi")

@reboot /path/to/script/script.sh

At boot, the script is launched (I checked file.txt), but the window opened by xfce4-terminal is not there. And... 'Systemd' looks like big Berta for just launching a script at boot....

Any idea? thank you folks!

marked as duplicate by jasonwryan, Anthon, Archemar, Jeff Schaller, GAD3R Sep 22 '17 at 13:22

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Could you add the whole script as well as the output of crontab -l? Above all: use full paths for any command in a crontab (e.g. /bin/bash /home/user/path/to/script if the script is not executable by itself) – Fiximan Sep 22 '17 at 7:30
  • If "Any idea?" is your question, anything posted as "Your Answer" is valid and correct. – Anthon Sep 22 '17 at 8:44

Think about it for a while. You reboot your computer and go and make a cup of coffee. The cron job tries to run, but where should it open the terminal? You're not even logged in...

Cron jobs are not run in the same environment as your interactive GUI environment, and you may therefore not generally schedule cron jobs as if they were ordinary commands typed at the command prompt without taking care to set up the needed environment variables etc. that the cron job needs to run.

In this case, it's not just a matter of a few environment variables, but that fact that the user may not even be logged in when the cron job runs. A graphical terminal requires a desktop environment to be present to run.

My guess is that you want to start your command each time your start your desktop environment (on login, rather than on reboot).

To do that in XFCE, either go Settings->Session and Startup->Application Autostart and clicking, Add, or create a file with the .desktop extension in ~/.config/autostart/ (this directory may not exist, so you may have to create it).

The file should look something like

[Desktop Entry]

Where /home/user/bin/script.sh is a script that does what you want to do.

(The above taken from an XFCE forum thread and I don't know if it works as I'm not even running X11)

Also related: Xfce initialization script

  • Your answer is clear; I have nothing to add. But not even running X11? how about surfing web with cli? is it confortable honestly? – achille Sep 22 '17 at 10:37
  • @achille Windows 10 laptop (for work reasons). Otherwise command line only in OpenBSD. – Kusalananda Sep 22 '17 at 10:52

Not the answer you're looking for? Browse other questions tagged or ask your own question.