how to set cron to display gui application
You can do this by setting the DISPLAY
variable to :0
. For instance:
* * * * * export DISPLAY=:0; gedit
This crontab line will open the gui software gedit every minute.
Launching an external GUI application from Python via crontab
Cron run in a specific environment, without display manager. If you try to do a echo $DISPLAY return null.
You need to set DISPLAY in your command, like that:
* * * * * DISPLAY=:0 <YOUR-COMMAND>
if your display is not 0, you can find, in X server with ps aux | grep Xorg
Running a tkinter GUI using crontab
The sudo will run without a tty and display that is why you command won't work.
Try having xvfb installed and use
0 18 * * * cd /home/pi/gui && xvfb-run python3 gui.py
Update-1: 22-Jun-18
If you want to use your actual display then you need to make sure that you use below command
XAUTHORITY=/home/<user>/.Xauthority DISPLAY=:0 python3 gui.py
And also make sure the cron is for your user. The default DISPLAY
is :0
.
When you have a XServer (GUI display), you cannot just connect to it without an authorization. When system start it creates a file and that location is stored in environment variable XAUTHORITY.
When you run a cron, you have limited environment variables. There is no existing XAUTHORITY
or DISPLAY
defined
to be able to connect to display you need. So you need to define every environment variable that would be required by your program
So you define DISPLAY=:0
to select the default display and you need to set XAUTHORITY=/home/<user>/.Xauthority
to prove that you are authorized to connect to the display
How to show a Kivy GUI using cron planner?
The solution was to change the command behaviour to X application
(rather than Default behaviour
). After that change, the console shows up and the GUI is displayed.
Cron job: how to run a script that requires to open display?
You will need a valid DISPLAY and XAUTHORITY to use X-Programms in Cron!
To set DISPLAY is very easy, type in the Bash:
export DISPLAY=":0.0"
In order to get a valid XAUTHORITY you have to look for it.
Under Debian/Gnome/gdm3 they are saved in var/run/gdm3/*/database
I used the following script:
export DISPLAY=":0.0"
[ -z $USER ] && USER=$( who | awk '{ print $1 }' | sort | uniq >/tmp/test )
for I in /var/run/gdm3/*; do
AUTHUSER="`echo $I | awk -F '-' '{ print $3 }'`"
for J in $USER; do
[ "${AUTHUSER}" = "${J}" ] || continue
USER="$J"
export XAUTHORITY="${I}/database" && break
done
done
sudo -u ${USER} /Path/to/xProgramm
The Var $USER can be empty, than the script looks for a valid user, otherwise you can tell the script the var!
Related Topics
How to Show a Gui Message Box from a Bash Script in Linux
How to Get 'Find' to Ignore .Svn Directories
Rsync Copy Over Only Certain Types of Files Using Include Option
How to Make Mv Create the Directory to Be Moved to If It Doesn't Exist
How to Check If Smtp Is Working from Commandline (Linux)
Unix: How to Delete Files Listed in a File
Cross-Compile a Rust Application from Linux to Windows
How Do Unix Domain Sockets Differentiate Between Multiple Clients
In Bash, How to Add a String After Each Line in a File
Display Two Files Side by Side
Limitations of Intel Assembly Syntax Compared to At&T
Fastest Way Convert Tab-Delimited File to CSV in Linux
How to Count Number of Files in Each Directory
Memory Limit to a 32-Bit Process Running on a 64-Bit Linux Os
Why Is Rcx Not Used for Passing Parameters to System Calls, Being Replaced with R10
Crt1.O: in Function '_Start': - Undefined Reference to 'Main' in Linux