[CentOS] Display a warning message at a certain time ?

Marko A. Jennings markobiz at bluegargoyle.com
Thu Feb 4 16:47:20 UTC 2010


On Thu, February 4, 2010 11:26 am, Geoff Galitz wrote:
>
>> I think the problem boils down to this :
>>
>> "How can I run a graphical application from crontab ?"
>>
>> I gave it a shot with a simple one (/usr/bin/gcalctool) and didn't
>> succeed either.
>>
>
>
>
> I think if you did something like this:
>
> ----------
>
> #!/bin/sh
>
> # set DISPLAY
> export DISPLAY="localhost:0"
>
> # send the message
> /usr/bin/xmessage -timeout 120 "This is my message"
>
> # exit cleanly
> exit 0
>
> ---------
>
>
> You'd be ok.  Run that as a script, making changes for your system where
> appropriate and then run that script from cron.  Cron makes very few
> assumptions about your environment, your PATHS and other environmental
> variables are not getting set. If you run this a script suing "#!/bin/sh"
> you should get a default environment as defined by your installation.

The following worked fine for me on a stock 64-bit CentOS 5 box:

17 11 * * *     export DISPLAY=:0 && /usr/bin/xmessage -nearmouse "test
message"

However, that was executed from a non-root crontab and the same user was
the owner of the X Windows session at the time.  When I tried to run the
same thing from root's crontab a minute later, it failed because root
could not open the display.  Executing "xhost +" did the trick, so you
might want to take a look at display permissions.

Marko


More information about the CentOS mailing list