Python script to run startup - insserv: command not found

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
garethfoote

Python script to run startup - insserv: command not found

Post by garethfoote »

Hi there,

I am trying get a python script to run on startup using insserv or executing the script using /etc/rc.local. The python script enables keyboard shortcuts for snapping windows to the edges of the screen (https://github.com/paulswartz/gnome-shell-grid).

When I use rc.local I found that I get errors related to the display presumably because the screen isn't ready at the point that rc.local is executed. Here is the error log:

Code: Select all

/usr/lib/python2.7/dist-packages/gtk-2.0/gtk/__init__.py:57: GtkWarning: could not open display
  warnings.warn(str(e), _gtk.Warning)
Traceback (most recent call last):
  File "/home/gareth/bin/gnome-shell-grid/gnome-shell-grid.py", line 192, in <module>
    main()
  File "/home/gareth/bin/gnome-shell-grid/gnome-shell-grid.py", line 147, in main
    display = Xlib.display.Display()
  File "/usr/lib/pymodules/python2.7/Xlib/display.py", line 83, in __init__
    self.display = _BaseDisplay(display)
  File "/usr/lib/pymodules/python2.7/Xlib/display.py", line 65, in __init__
    apply(protocol.display.Display.__init__, (self, ) + args, keys)
  File "/usr/lib/pymodules/python2.7/Xlib/protocol/display.py", line 44, in __init__
    name, host, displayno, screenno = connect.get_display(display)
  File "/usr/lib/pymodules/python2.7/Xlib/support/connect.py", line 65, in get_display
    return mod.get_display(display)
  File "/usr/lib/pymodules/python2.7/Xlib/support/unix_connect.py", line 59, in get_display
    raise error.DisplayNameError(display)
Xlib.error.DisplayNameError: Bad display name ""
Alternatively I was going to try using insserv but whenever I try to run insserv I get 'command not found'. To ensure it was installed I ran 'apt-get install insserv' and I am apparently at the latest version already.

I would like to remove and reinstall but when I try to remove insserv I get a warning that I am about to do something dangerous and potentially harmful.

So I have 2 questions really:

1) Can I use insserv to get this script to run at startup after the display is ready?
and if so:
2) why can I not run insserv if it is apparently installed?

Thanks in advance,
Gareth
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
xenopeek
Level 25
Level 25
Posts: 29614
Joined: Wed Jul 06, 2011 3:58 am

Re: Python script to run startup - insserv: command not foun

Post by xenopeek »

As this is about scripting, moving it here.

Why not just add an entry in Startup Applications for your script?
Image
Locked

Return to “Scripts & Bash”