Run Shell Script After Xserver Is Started

Run shell script after XServer is started?

According to this link .xinitrc in your home directory will be read and executed, otherwise the default /etc/X11/xinit/xinitrc is used. So you should be able to create this file and have the shell script started.

Execution of some command every time a xerser starts: Turn on keyboard leds on startup by `xset led led on`

You could edit the /etc/rc.local file which will be executed after boot and run level changes. You can just throw the command right in there. You may also be able to use ~/.xinitrc or ~/.xsession depending on your specific setup (I'm not familiar with Ubuntu Mate).

How to run a shell script at startup

The file you put in /etc/init.d/ have to be set to executable with:

chmod +x /etc/init.d/start_my_app

As pointed out by @meetamit, if it still does not run you might have to create a symbolic link to the file in /etc/rc.d/

ln -s /etc/init.d/start_my_app /etc/rc.d/

Please note that on the latest versions of Debian, this will not work as your script will have to be LSB compliant (provide at least the following actions: start, stop, restart, force-reload, and status):
https://wiki.debian.org/LSBInitScripts

As a note, you should always use the absolute path to files in your scripts instead of the relative one, it may solve unexpected issues:

/var/myscripts/start_my_app

Finally, make sure that you included the shebang on top of the file:

#!/bin/sh

running shell script starts new shell instead of running the shell script

The key was this line in /etc/bash.bashrc

source /usr/sbin/start-systemd-namespace

Awhile back I got systemd working from some instructions elsewhere on the net. It must have added this line. It causes an entirely new shell to start when you're using another shell like zsh. After commenting it out, voila, no more problem.



Related Topics



Leave a reply



Submit