Key words: crontab, Shell, Y-send, Xauth, xhost
I wrote a script to run it on the terminal:
#! /Bin/ShExport display=:0Time='Awk '{Print $1}'/Proc/Uptime'Text="You have been running for $ {time %. *} hours. Please take a rest. The system will be shut down in 5 minutes. Please save it in time."If[$ {Time%. *}-Ge7200]ThenNotify-Send $ textFi
But it cannot be written to crontal:
# M h Dom mon Dow usercommand
* *** Root export display =:0& Amp;/home/XXX/policy.Sh
Why?
========================================================
Update: after finding the cause, modify it and OK.
First, you can use/home/cmdy. Sh>/home/log.txt 2> & 1
Deubg to check whether crontab is executed.
I can execute it, but the GUI is not displayed. Why. The display variable settings are incorrect.
However, display =: 0 is added to crontab.
Later, it was mentioned on the Internet that if the GUI is executed on the terminalProgramAfter switching to a user, you must reset the DISPLAY variable to display the data,
The reason is that the. Xauthority file already exists in the/home directory. If you use root to execute this variable, it cannot be displayed without resetting it;
Then I can use the original login user to execute the command, and change it to the following:
# M h Dom mon Dow usercommand*****Xxx(Myname)Export display =:0/Home/XXX/notify.Sh
Success!