Boston Linux & UNIX was originally founded in 1994 as part of The Boston Computer Society. We meet on the third Wednesday of each month at the Massachusetts Institute of Technology, in Building E51.

BLU Discuss list archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Discuss] cron notifications to GUI front end

On Thu, Mar 28, 2019 at 11:41:09AM -0400, Rich Pieri wrote:
> On Thu, 28 Mar 2019 11:23:26 -0400
> Jerry Feldman <gaf.linux at> wrote:
> > One idea I had was to write a small GUI that would cancel any
> > currently scheduled shutdown and reschedule and notify the user when
> > the shutdown is imminent. If the user logs off, the shutdown would
> > still be in effect.
> I don't think that's going to work the way you expect. One big problem
> is that a process running from cron can't directly access your X server
> so it can't send GUI notices.

That's not actually true, though it will take a little bit of hackery
to make it work.

Modern Linux systems depend on MIT-MAGIC-COOKIE-1 authentication to
allow access to the X display.  You control this through the xauth
command.  Once you're logged in, you can see the cookies you have,
like so:

$ xauth list
myhostname/unix:0  MIT-MAGIC-COOKIE-1 1234567890abcdef1234567890abcdef

[You may have more than one, but chances are the /unix:0 entry is the
one you want.]

So when you log in, e.g. in your .xsession file or what have you, dump
this to a file, say $HOME/tmp/xauth, and make sure it's only readable
by you (and of course root).  Then change your cron job to a script
that adds that line to roots xauth, and runs your gui thingy.  You can
do that with something like:

xauth add `cat ~myuser/tmp/xauth | grep "unix:0"`

FWIW I tested this by logging into a VC on my desktop as root, setting
up xauth essentially as above, and then running xeyes.  Worked like a
charm. :)

Then, in your cron script, if the gui thingy fails (e.g. because
there's no display to connect to, or auth failed, etc.), execute the
shutdown command.  Otherwise don't.  Obviously the gui widget thingy
needs to exit with a corresponding exit code so you can test it

Personally, I would never do this, but if I were to want to do this, I
kinda like this approach--though I think Rich's is fairly equivalent.
I suspect there's not a ton of difference in the code you'd need to
write for either solution, though my guess is the client-server
solution would require slightly more, depending on the language and
GUI toolkit you chose.  I would definitely use Python, but then I'd
need to re-research GUI options for the easiest.

Derek D. Martin   GPG Key ID: 0xDFBEAD02
This message is posted from an invalid address.  Replying to it will result in
undeliverable mail due to spam prevention.  Sorry for the inconvenience.

BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!

Boston Linux & Unix /