A couple of general script questions

I want to run a shell script following boot, after startx and also after desktop start up where do I add them so that updates wont mean that I have to add my changes again? Several scripts used to call a script for this sort of use in the past but I can’t find any signs of them now. There doesn’t appear to be any information on this area in leap 42.2 doc’s.

The last questions relate to how scripts run.

I want a script to launch a desktop application but am not sure what the correct command is? This script will be run from the start button menu.

The script will launch the desktop file part way through and will need to continue after the desktop applications closes. Set up, launch the application and then clean up when it closes. Will the suggested command do this and does the script need anything special to achieve this?

Finally what happens if the machine is rebooted or shut down via the desktop. Will the script still run to completion?

Hopefully thanks.

John

Hi
Since you want it to complete if the system is started/rebooted/shutdown then you probably need to look at systemd and user service files (/etc/systemd/user).

You can look at adding a <somename>.desktop into the /home/.local/share/applications directory and update the desktop database so it’s added to the menu (the categories will put it where you want it) and call your script from this eg /usr/bin/myscript. If you want it to autostart then the users ~/.config/autostart directory. You can set your main script to check for files and such to either overwrite or skip etc.

You can create an entry in your Desktop application settings, but that depends on whatever Desktop is running.
You’ll find info on this in the Desktop documentation, not the main OS documentation.

A bit unclear.
You need to clearly define exactly each requirement and then find a solution for each.
So,
Is this application already installed or needs to be installed?
If the application is installed, do you also need to add to the application launch menu? Solution depends on what Desktop you’re running.
Launching an application is a completely separate issue from installing and configuration. There are a number of ways you can invoke the application once it’s installed, and how it might be done “depends” on a lot of things. If you don’t understand how to evaluate this, you’ll probably have to post a detailed description of the application for others to help.

It depends. Depends on the running process, how the application was invoked, its running context. And, it also depends on the type of shutdown. Shutdowns can be sudden and terminate processes, or can wait until running processes have ended on their own.

TSU

I’m not really sure what you are trying to do.

For the KDE desktop, you can add a startup command via
Configure Desktop –> Startup and Shutdown –> Autostart (tab).

For the Gnome desktop, you can set a startup command via Tweak Tool, and what you set there also works for KDE and XFCE.

You can also put something in your shell startup file. But you have to be careful there, because shell startup files run at session startup, but they also run at other times. So you might need to set an environment variable that you can check to avoid running twice.

With KDE, you can have a script that runs on desktop shutdown. I’m not sure of other desktops.

;)What I want to do seems pretty clear to me.

First I don’t have any problems with adding a desktop file to run a shell script. I’ve already done that to launch dstat with certain settings. Done via edit start button so will be placed in the default directory as per xdg settings. That’s fine for my needs. No need to make it user local. The script will need to do the following

1 - Set up an environment for a desktop application. What that entails varies. It will generally be configuration data.

2 - Launch the application

3- Restore things to what they were when the application closes. That can include changes to what was originally set up.

Crashes and power fails don’t matter much because boot will set things up again but recent configuration changes will be lost. All that matters is that the script does run when the application closes even if it closes due to the various desktop power/session options. If switch user happens to work in a different way to the others that doesn’t matter as there are no other users in that sense on the machine.

I would be sorely disappointed in linux if it can’t have a script that calls something else and then completes when the something else has finished or closed. The script needs tying to what ever the something is so separate start up and shut down scripts aren’t a sensible way of doing this sort of thing. Those are only any good for settings for the entire desktop.

John

On Wed 31 May 2017 10:16:01 AM CDT, ajohnw wrote:

;)What I want to do seems pretty clear to me.

First I don’t have any problems with adding a desktop file to run a
shell script. I’ve already done that to launch dstat with certain
settings. Done via edit start button so will be placed in the default
directory as per xdg settings. That’s fine for my needs. No need to make
it user local. The script will need to do the following

1 - Set up an environment for a desktop application. What that entails
varies. It will generally be configuration data.

2 - Launch the application

3- Restore things to what they were when the application closes. That
can include changes to what was originally set up.

Crashes and power fails don’t matter much because boot will set things
up again but recent configuration changes will be lost. All that matters
is that the script does run when the application closes even if it
closes due to the various desktop power/session options. If switch user
happens to work in a different way to the others that doesn’t matter as
there are no other users in that sense on the machine.

I would be sorely disappointed in linux if it can’t have a script that
calls something else and then completes when the something else has
finished or closed. The script needs tying to what ever the something is
so separate start up and shut down scripts aren’t a sensible way of
doing this sort of thing. Those are only any good for settings for the
entire desktop.

John

Hi
Sounds more like you need to look at kiosk mode (or just boot an
image)… if you start a script and use ampersand (a &) at the end
it will background it’s self.


Cheers Malcolm °¿° SUSE Knowledge Partner (Linux Counter #276890)
openSUSE Leap 42.2|GNOME 3.20.2|4.4.62-18.6-default
If you find this post helpful and are logged into the web interface,
please show your appreciation and click on the star below… Thanks!

Thanks Malcolm. A good web page on this subject - maybe.

http://www.thegeekstuff.com/2010/12/5-ways-to-execute-linux-command/

Looks like the command I will need is


$ nohup ./my-shell-script.sh &

Then if the /etc/systemd/user location for the script you mentioned works out all should be ok. There isn’t much about on this subject other than SIGTERM is issued on shut down to give things time to finish what they are doing. That would mean that the script would have to pole for that event or assume that the application responded to it.

John

Hi
Yes, if you use the systemd service you can look for a (or generate) signal and then wait for you job to finish before a complete shutdown.