How to start script during booting or after

Hello, I suppose I have a simple question for linux advanced users.

I have a script located in /home/user/software/bin/script.sh

And I wanted to start it during booting so I have used boot.local.
I put there line

sh ‘/home/user/software/bin/script.sh’

but when I start booting the PC is blocked and does nothing, only way is to restart and delete the line from file.

Please, how to do it?

Thank you,

Martin

On 02/03/2012 04:56 PM, atilius wrote:
> Please, how to do it?

that depends on what version of openSUSE you are using…because things
change from time to time (if you are using before 12.1 the answer i can
give, if you are using 12.1 i don’t know, but i know it is different)

but, since i don’t understand your using
“/home/user/software/bin/script.sh” i ask when you declare a system
version, please also state when in the boot process you what the
script to be run…

that is, do you want it run after the desktop has started? (if you use a
desktop–if you do, please tell us which one and version)

or do you want it started before X or the DE is started?

if you don’t know when, you might just mention the purpose of the script
and what it is doing, generally…


DD
Read what Distro Watch writes: http://tinyurl.com/SUSEonDW

I use 11.3 version.

It is DLNA server so when desktop is ready, this would be ready too. I use KDE 4.7 and i have tried to put the script also in settings of KDE but no success too.

Thank you,

Martin

First off, it should not be boot.local but after.local. What you want is probably to run your script at the end of the init process, not at the end of the boot process. This is what after.local does in 11.4 and previous versions and in 12.1 while booting sysinit. Now 12.1 uses systemd (by default), another init process which doesn’t make use of after.local. Have a look at this blog article about how to restore after.local functionality under systemd: https://forums.opensuse.org/content.php/120-systemd-and-using-the-after-local-script-in-openSUSE-12-1

Maybe it’s just pausing for five minutes - systemd’s time out.

It depends what your script is doing. systemd’s after.local is much more like a “during local”. If your script needs a daemon or a service that hasn’t started, it won’t do what you want. In this case you might have to insert a delay or use such tricks: http://forums.opensuse.org/english/other-forums/development/programming-scripting/469832-running-commands-depend-process-being-started-after-local.html

Then you have to use /etc/init.d/after.local. Create the file if it doesn’t exist. It does exist on 11.4, but maybe not in 11.3.

#! /bin/sh
#
# Copyright (c) 2010 SuSE LINUX Products GmbH, Germany.  All rights reserved.
#
# Author: Werner Fink, 2010
#
# /etc/init.d/after.local
#
# script with local commands to be executed from init after all scripts
# of a runlevel have been executed.
#
# Here you should add things, that should happen directly after
# runlevel has been reached.  Common environment
# variables for this are:
#  RUNLEVEL  -- The current system runlevel.
#  PREVLEVEL -- The previous runlevel (useful after a runlevel switch).
#

Does it start a server or a client? If it’s a client, you can put your script in your ~/.kde4/Autostart. If it’s a server, put it in /etc/init.d/after.local. If it doesn’t work, check your script.

On 02/03/2012 05:36 PM, atilius wrote:
>
> I use 11.3 version.
>
> It is DLNA server so when desktop is ready, this would be ready too. I
> use KDE 4.7 and i have tried to put the script also in settings of KDE
> but no success too.

remove the line from boot.local, and instead mark the script as
executable and put it in

/home/[bootingUser]/.kde4/Autostart

it will then start up as part of KDE…and won’t be lost when you
format the root partition to move to a supported version…

openSUSE 11.3 went past its end of life a couple of weeks ago (January
20th 2012, cite: http://en.opensuse.org/Lifetime)–and, if that machine
is exposed to the internet or any potential “bad guys” have access, you
should move to a supported version sooner, rather than later…)


DD http://tinyurl.com/DD-Caveat http://tinyurl.com/DD-Hardware
http://tinyurl.com/DD-Software
Read what Distro Watch writes: http://tinyurl.com/SUSEonDW

I have used aftr.local file and it works. Thank you all of you for your assistance. Martin

While the OP and those answering above might fully understand the security implications of the method used above and it even might be that it is not that severe as it may look, I want to add a severe WARNING for hose who come later at anytime to this thread and might think this is a save way of doing things.

Alll the processes run at boot time, including after.local are executed which process owner root. Thus the progam /home/user/software/bin/script.sh is executed as root. Now it looks as if /home/user is the home directory of user user. This is not sure because the OP did not show anything about this directory or /softwarescript.sh within it. But when this is the home directory of user user and this user also owns* software* and software/bin and software/script.sh, user is able at any time to change script.sh to do the most horrible things to the system (at boot time).

Thus, do not do this when the script/program is in the domain of an ordinary user!

I repeat, in this case /home/user/bin/script.sh might all be owned by root and protected sufficiently, but the use of a place within /home might lure innocent people in thinking that putting such a script in one’s home directory is a smart thing to do. Which it is not.

BTW, when* /home *is on a seperate partition, there is another con for doing this. When */home *is not available for whatever reason, there is a problem while booting. All and everything needed during a startup of the system should be available in the root partition.

On 02/03/2012 07:46 PM, hcvv wrote:
> I repeat, in this case -/home/user/bin/script.sh -might all be owned by
> root and protected sufficiently

heh…since we didn’t know the contents of the script, i kinda expected
that if it had to be executed as root s/he would come back and say it
didn’t work…

so, if we don’t hear more i guess it is a user level script that would
have otherwise been root powered from after.local

i’m not sure which is worse, root executing after.local script that
should not be, or ‘user’ trying to run a system script from the kde
autostart directory… :wink:

but, i do agree with all your cautions…


DD
Read what Distro Watch writes: http://tinyurl.com/SUSEonDW