2

I really would like to be able to use crontab to update something every 3hrs, BUT crontab won't run my script with enough priveleges to run a GUI.

Clarification: I have a complicated script that generates a picture (based on the current available web content from a couple of servers) every 3hrs - I want to have it display what it is that it's doing so I know whether it failed or not.

I've tried: 1. Adding a file to /etc/cron.d/myscript for cron to run 2. variations of xdg-open, gnome-terminal, mrxvt -e, env DISPLAY=:0.0, root /usr/local/bin/myscript 3. Editing my user cron -- crontab -u username -e

Myscript is a complicated little beastie that downloads a picture (which is updated every half hr) then downloads a different websites webpage as index.html - sed's it, finds the particular image it needs (based on today's date & time) then crops and transforms it, with imagemagick.

3
  • If you are talking about user privileges, you can create crontab entries for root user to get the needed privileges.
    – Khaled
    Jan 31, 2011 at 7:33
  • 2
    Displaying stuff on a different user's display is highly non-trivial, even if you are root. What is this "thing" you want to run every 3 hours, and what do you want to show to the user? There are several notification services on Linux (copycats of "Growl" for Mac) which may provide what you need.
    – unixtippse
    Jan 31, 2011 at 7:51
  • 1
    Please provide more details of exactly what you are trying to do, what you have attempted, and where it's failed. Jan 31, 2011 at 8:14

3 Answers 3

3
man xauth
man xhost

You can try xhost local: as the beginning.

4
  • Thanks for the suggestion! I've tried editing with crontab -e --- 42 23 31 1 * xhost local: /usr/local/sbin/myscript.sh - but it didn't even run in the background. Jan 31, 2011 at 10:46
  • You need to run "xhost local:" once per X server session. It's not a prefix for other commands, it just allows to connect to X server from local connections.
    – poige
    Jan 31, 2011 at 12:08
  • So, to clarify, it does or doesn't go in the crontab entry? - Do I put this command into my script instead? Jan 31, 2011 at 17:45
  • man, why don't you read man? :) Here it goes: «… The initial access control list for display number n may be set by the file /etc/Xn.hosts, where n is the display number of the server. See Xserver(1) for details. …»
    – poige
    Jan 31, 2011 at 18:00
1

If you want to open a window on the user's desktop, you need to export the X11 authentication info from your user context and provide it to your root context.

As the user, export the xauth info:

$ xauth extract /home/foo/xauth-foo $DISPLAY
$ echo $DISPLAY
:0.0

Then, as root, import it and start your X client:

# xauth merge /home/foo/xauth-foo
# export DISPLAY=:0.0
# xclock

This is untested from my notes. I haven't had a use case for this in at least 5 years.

2
  • is the xauth-foo file likely to be .Xdefaults? I'm not sure which file to perform xauth extract. Is $DISPLAY the only variable we are extracting with xauth? Jan 31, 2011 at 17:34
  • No, xauth-foo is xauth-foo. Call it what you like. It's especially unrelated to .Xdefaults. It's somewhat related to .Xauthority, though, but still different from it, because it's a container for transferring xauth info into another context. $DISPLAY is the display from which you want to export xauth info.
    – unixtippse
    Jan 31, 2011 at 21:05
0

I actually just asked this question myself and managed to answer it after getting some guidance ( Source 1 & Source 2). However, this was for the raspberry Pi so you may need to use some other command.

gnome-terminal -e command

xterm -e command

konsole -e command

terminal -e command

lxterminal -e command

By using the command lxterminal -e command, I can make the terminal open a new window. But that's not all that needs to be done. Specify the path rather than rely on environment variables in crontab... and I was already using PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin so I just went with that. Then create a simple script to use in crontab, which calls another script.

#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
export DISPLAY=:0.0
lxterminal -e /home/pi/Public/./test

Crontab (command crontab -e) ends up looking like...

PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
* * * * * /home/pi/Public/test2

Which calls the final script test.

#!/bin/bash
echo 'This is a test.'
echo 'This is a written test with lxterminal -e for real.' >> /home/pi/Public/testwrite.txt
sleep 10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .