Crontab not opening gnome-terminal

Configured crontab to run a script.

crontab config

* * * * * export DISPLAY=:0 && sh $HOME/path/to/script >> /tmp/error.llog 2>&1

Script

gnome-terminal --window -e "sudo ifconfig wlo1 down; sleep 1; sudo ifconfig wlo1 up"

Whenever the script is executed I'm getting the following error message.

Error constructing proxy for org.gnome.Terminal:/org/gnome/Terminal/Factory0: Could not connect: Connection refused

Locale configs

LANG=en_IN
LANGUAGE=en_IN:en
LC_CTYPE="en_IN"
LC_NUMERIC="en_IN"
LC_TIME="en_IN"
LC_COLLATE="en_IN"
LC_MONETARY="en_IN"
LC_MESSAGES="en_IN"
LC_PAPER="en_IN"
LC_NAME="en_IN"
LC_ADDRESS="en_IN"
LC_TELEPHONE="en_IN"
LC_MEASUREMENT="en_IN"
LC_IDENTIFICATION="en_IN"
LC_ALL=


Solution 1:

You really do not want to open Gnome Terminal this way. Cron is not designed to be used for starting graphical applications. Use "autostart" in your desktop environment to automatically open a terminal emulator.