0

I well used the command "crontab -e" and added this task :

* * * * * * bash /home/user1/launcher.sh

The content of launcher.sh is :

#!/bin/bash

PATH=/home/user1/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

/usr/bin/gedit

Permissions of launcher.sh are 777.

I was expecting to see gedit launched every minute....but nothing happens. Why ?

I think crontab well launch "launcher.sh", as i can see in syslog :

Feb  7 22:58:01 librempc CRON[5922]: (user1) CMD (bash /home/user1/launcher.sh)
Feb  7 22:58:01 librempc CRON[5921]: (CRON) info (No MTA installed, discarding output)
floupinette
  • 150
  • 11
  • 5
    The `DISPLAY` environment variable isn't set in the `cron` environment, so it doesn't have access to the X server. – Barmar Feb 07 '22 at 22:07
  • As @Barmar mentioned , you can add "DISPLAY=:0 " to your crontab record like * * * * * env DISPLAY=:0 /path/to/script , also try running it as your user not the root as x-server authority may have another opinion – Tamer Elfeky Feb 07 '22 at 22:12
  • If you are trying to experiment with cron, then a non-interactive command would be a much better suited target. For example, `date > /tmp/cron.timestamp`. – John Bollinger Feb 07 '22 at 22:27

1 Answers1

1

By default, Cron executes tasks with very few environnement variables.

It was well explained there : cron & the environment variables

For the environment variable "PATH", it's possible to define it in the bash script of the task itself :

PATH=/home/user1/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

But for the environment variable "DISPLAY" (which is mandatory if the task you launch display something), it must be precised in cron file directly.

* * * * * * DISPLAY=:0 bash /home/user1/launcher.sh
floupinette
  • 150
  • 11