I neglected to mention that the cron script also needs to set DISPLAY, most likely to ":0", and then export it. That's probably not a surprise to any veteran X users though...
On Fri, Mar 29, 2019 at 03:02:42PM -0500, Derek Martin wrote: > On Thu, Mar 28, 2019 at 11:41:09AM -0400, Rich Pieri wrote: > > On Thu, 28 Mar 2019 11:23:26 -0400 > > Jerry Feldman <[email protected]> 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 > appropriately... > > 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 http://www.pizzashack.org/ 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. > > _______________________________________________ > Discuss mailing list > [email protected] > http://lists.blu.org/mailman/listinfo/discuss -- Derek D. Martin http://www.pizzashack.org/ 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. _______________________________________________ Discuss mailing list [email protected] http://lists.blu.org/mailman/listinfo/discuss
