Im using Linux Mint.

I have written a python script that is designed to not be accessible to the logged in standard user but is still be executed while they are logged in. It is to run and log them out if a certain field is set in a mysql database and show a dialog saying "you're being logged out blah".

If I run the python script as the standard user all is well and they get logged out.

If I run the python script as the admin user I get:

glib.GError: Unable to connect to server

when it tries to show the dialog box

If I re-run the script with the admin user and sudo, it works.

The idea is for this to run from cron, and unless I can get cron to run the script as the admin user with sudo it's not going to work.

Any help?


this is the two gui parts of the script

this part is called every time the script runs and will show a notification with the amount of time the user has left

    n = pynotify.Notification("Time Left", str(u.timeLeft / 60)+" Minutes remaining")

    n.set_timeout(10000) # 10 seconds
    helper = gtk.Button()
    icon = helper.render_icon(gtk.STOCK_DIALOG_WARNING, gtk.ICON_SIZE_DIALOG)
    try :

This part only runs if certain conditions are met ie the time they have left is under 5 mins.

def getText():
    #base this on a message dialog
    dialog = gtk.MessageDialog(
    dialog.set_markup('Your time limit is nearing the <b>end</b>')
    entryUser = gtk.Entry()
    entryPass =gtk.Entry()
    entryUser.connect("activate", responseToDialog, dialog, gtk.RESPONSE_OK)
    hbox = gtk.HBox()
    hbox.pack_start(gtk.Label("Username:"), False, 5, 5)
    hbox.pack_start(gtk.Label("Password:"), False, 5, 5)
    dialog.format_secondary_markup("Please enter a new voucher <i>Username</i> and <i>password</i> to carry on your current session")
    dialog.vbox.pack_end(hbox, True, True, 0)
    username = entryUser.get_text()
    password = entryPass.get_text()
    voucher = {'username':username,'password':password}
    return voucher

2 Answers 2


Why don't you add the cronjob to the standard user's crontab?


If it has to go in the admin user's crontab, and you have to run it with sudo for it to run properly, then you one solution might be to modify your sudoers file to allow the admin user to run the python script without a password.

admin hostname = NOPASSWD: /path/to/python/script.py

Then in the admin user's crontab file:

0 0 * * * sudo /path/to/python/script.py > /tmp/script.py.log 2>&1

To run the script at midnight and log output to /tmp/script.py.log (so you can see where/if errors occur).

This assumes that your use of admin user indicates that you have a non-root user with the username admin. Otherwise, by default, the root user is allowed to run sudo commands without authenticating.

  • Why not use the normal user's crontab: because then the normal user could remove or kill the job. I think that Steve means root by admin; the problem is that the Python script is trying to contact some notification server running as the normal user. Commented Nov 16, 2011 at 0:54
  • thanks @Gilles. that makes sense. i guess i think about things from a "server" point of view, where we don't usually use things like notifyd. :) Commented Nov 16, 2011 at 2:24
  • @Gilles yes thats correct I dont want the user to be able to kill it, the user I refer to as admin is the 1st user I setup on mint I think mint follows the same policy as ubuntu the first user is a member of the admin group and the admin group has all SUDO rights
    – squareborg
    Commented Nov 16, 2011 at 10:34

You can just add it to root's crontab: sudo crontab -e

It will run as root at the specified schedule. See man 5 crontab for the crontab file format.


*/5 * * * * /path/to/your/script
  • Hi thanks but the script runs but it wont display the dialog box im guessing its getting the same glib.GError: Unable to connect to server error
    – squareborg
    Commented Nov 15, 2011 at 16:15
  • Is this application an X Application (with a GUI)? In this case you need to set the DISPLAY variable to export :0 in your crontab.
    – Matteo
    Commented Nov 15, 2011 at 16:25
  • @Matteo Glib is the part of Gnome that doesn't require X (mostly data structures and communication facilities). I think it's looking for a notifyd, not for an X server. Commented Nov 16, 2011 at 0:56
  • @Gilles and mateo, yes this does have a gui part to it, its to show a notification and a dialog box, does cron need something else exporting to hook into the current users session? Ive tried the DISPLAY=:0 in roots crontab same thing happens glib error
    – squareborg
    Commented Nov 16, 2011 at 9:37

You must log in to answer this question.

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