0

I need the following sample script to run when OpenSuSe 11 is booting:

#!/bin/sh
i=0;
while true; do
    "SOME COMMAND FOR SAVING i TO ANOTHER PLACE" &> /dev/null
    i=$((i+1))
    sleep 1
done

So basically just add 1 every second on a variable and then send the variable to another system. I saved this script at /bin/user/script.sh

Starting the script from console works perfectly..

/bin/user/script.sh > /dev/null 2>&1 &

First I added this line to the existing /etc/init.d/boot.local that comes with OpenSuSe, however this was not working so stable. Sometimes it was started and sometimes not. I thought because of user rights, but even after

chmod 755 script.sh

The problem continues. So then I made my own /etc/init.d/myscript

Content of /etc/init.d/myscript:

#! /bin/sh
#
# /etc/init.d/myscript
#
### BEGIN INIT INFO
# Provides:          myscript
# Required-Start:
# Required-Stop:
# Default-Start:     3 5
# Default-Stop:      0
# Short-Description: Start myscript while booting
# Description:       ...
### END INIT INFO
#
#
#
case "$1" in
    start)
        echo "Starting myscript."
        /bin/user/script.sh > /dev/null 2>&1 &
        ;;
    stop)
        echo "Stopping myscript."
        killall -9 script.sh
        ;;
    *)
        echo "Usage: $0 {start|stop}"
        exit 1
        ;;
esac

Then I did the insserv command for my script:

insserv myscript

Starting and stopping from console works..

/etc/init.d/myscript start
/etc/init.d/myscript stop

but again no sign of life for myscript after booting.

What am I doing wrong? How can I successfully run a script every time when the system starts?

Update 2015.11.12: This script is working and starting correctly on boot on OpenSuSe 11.

1 Answer 1

0

Have you verified that insserv worked?

If you run chkconfig --list | grep myscript do you get any output?

5
  • chkconfig --list | grep myscript myscript 0:off 1:off 2:off 3:on 4:off 5:on 6:off On Yast2 I can also see myscript.. and running it from there also works perfeclty
    – Ñhosko
    Nov 11, 2015 at 17:08
  • So that indicates that it should start. Does a testrun of insserv -n give any error output? Nov 11, 2015 at 17:09
  • Another idea - I sometimes add debug points in my scripts. Try to get them to print a date/text to a log file somewhere in different parts of the script to see if it starts, where it blows up etc. Maybe that could help you see if it even launches? Nov 11, 2015 at 17:15
  • Thanks for the tip,, well it is actually running. Now looks like the problem is "SOME COMMAND FOR SAVING i TO ANOTHER PLACE",, can not start before other commands in the system. I will contact the distributor of this special command for more details.. Thanks for your help!
    – Ñhosko
    Nov 11, 2015 at 17:40
  • No worries at all - hope you get to the bottom of it. Things like this can drive you mad. I've had everything to the wrong start order to 'must use absolute paths' in the past. Good luck! Nov 11, 2015 at 18:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.