Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following Python script, chmod +x'd. When I run this script from the command line and Putty has not been started, it launches putty:

#!/usr/bin/env python
from __future__ import print_function

import shlex
import subprocess

output = subprocess.check_output(['ps', 'aux'])
found = False
for line in output.split('\n'):
    if line.endswith('putty -load test'):
        found = True

if not found:
    print("Starting Putty")
    print("Putty going strong")

However, if I don't start putty, then it will just keep saying "Starting Putty" (which I have directed to a file for logging).

My guess is that it has something to do with the display, but I'm not sure how to fix it or even exactly what I would look for.

share|improve this question

Turns out you need to set the display.

* * * * * env DISPLAY=:0 /home/wayne/.bin/run_putty

Or, if I had multiple monitors

* * * * * env DISPLAY=:0.0 /home/wayne/.bin/run_putty

And now it will check/run every minute.

share|improve this answer
Depending on your distribution, you may need to set XAUTHORITY as well. See Open a window on a remote X display (why "Cannot open display")? – Gilles Sep 26 '12 at 23:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.