Open an lxterminal window via shell script triggered by udev rule
Asked Answered
I

2

0

I'm trying to start a python script that waits for user input via a shell script triggered by a UDEV rule. After the input arrives the python script needs to make some database calls. I'm running into a couple different issues.

Here is the udev rule:

SUBSYSTEM=="usb" RUN+="/path/to/script.sh"

Issue #1 - I can't seem to get it to actually open the window. Here is what I have in script.sh:

#!/bin/bash
lxterminal -e /path/to/python_script.py

Here is the error I'm getting from udev:

'/path/to/script.sh'(err) '(lxterminal:4606): Gtk-WARNING **: cannot open display: '

Here is another version of the shell script which actually ran, but wasn't visible, and crashed when checking for input. Guessing because I'll need to re-route stdin if I ever get the terminal to open? Script:

export DISPLAY=0:; bash -c /path/to/script.sh

Error:

(err) name = input('Enter your name')
(err) 'EOFError: EOF when reading a line'

If I get rid of the input, I get this error:

[4859] exit with return code 0

This answer makes it sound like this isn't possible, but this is programming anything is supposed to be possible! https://unix.stackexchange.com/questions/119078/cannot-run-script-using-udev-rules

The end of this forum sounds like it's possible, but I'll need to use Zenity? https://ubuntuforums.org/showthread.php?t=759389

Any info from someone that's more familiar with udev would be great!

Isagogics answered 18/8, 2016 at 3:56 Comment(0)
P
1

For Issue #1;

lxterminal --command "python -i /path/to/python_script.py"
Piacular answered 18/8, 2016 at 8:18 Comment(1)
Thanks for the suggestion - unfortunately results in the same display warning :(Isagogics
I
0

I found the info I needed here: Scripts launched from udev do not have DISPLAY access anymore?

The script called by udev:

export DISPLAY=:0.0; export XAUTHORITY='/var/run/lightdm/root/:0'; /path/to/python.py

Then inside my python.py script:

cmd = ["zenity", "--entry", "--title='title'", "--text='{}'".format(var)]
response = (subprocess.check_output(cmd)).decode("utf-8") # Decode to a string
Isagogics answered 18/8, 2016 at 16:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.