This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Starting bash script on boot

Hi all,

Hopefully its an easy fix, I'm trying to start a bash script at startup that will run forever (while system is online).

I have a script, called statupdate

I have located it in /etc/init.d/

I have given it execute permissions

I have then put in a link to it under /etc/init.d/RC3.d/S99statupdate

This worked, but the system boot sequence never finished because the script started kept looping, preventing the system boot sequence to continue.

I then created another script called startupdate

that script simply started the main statupdate script. I tried with the following:

./statupdate &

OR

nohup ./statupdate & 

I swapped out the S99statupdate with S99startupdate (and gave it execute permissions)

The exact same issue occured.

Can anyone point out what I'm doing wrong?

Cheers,
Pazu


This thread was automatically locked due to age.
  • I suspect I've completed missed the point of the init script, the skeleton/readme isn't on the box i'm working on so I got a tad lost.

    If someone can point me in the direction of a step by step guide for init scripts that would be great.

    I have found a few guides such as:

    Managing Linux daemons with init scripts | Linux.com

    https://en.opensuse.org/openSUSE[[:P]]ackaging_init_scripts

    But they both refer to the application or executable, can I just use the script i want to run as the executable?

    Regards,
    Pazu
  • I have tried the following but get an error 'unknown service' when trying to add with chkconfig

    #!/bin/bash
    #
    # Run-level Startup script for the LCD Stat Updater
    #
    # chkconfig: 345 91 19
    # description: Startup/Shutdown LCD Stat Updater

    # if the executables do not exist -- display error

    if [ ! -f /etc/init.d/statupdate ]
    then
            echo "LCDStatusMon startup: cannot start"
            exit 1
    fi

    # depending on parameter -- startup, shutdown, restart 
    # of the instance and listener or usage display 

    case "$1" in
        start)
            # LCDStatusMon  startup
            echo -n "Starting LCD Status Monitor: "
            /etc/init.d/statupdate
            echo "OK"
            ;;
        stop)
      # LCDStatusMon shutdown
            echo -n "Shutdown LCD Status Monitor: "
            pkill -f statupdate
            echo "OK"
            ;;
        reload|restart)
            $0 stop
            $0 start
            ;;
        *)
            echo "Usage: $0 start|stop|restart|reload"
            exit 1
    esac
    exit 0
  • Hi all,

    Hopefully its an easy fix, I'm trying to start a bash script at startup that will run forever (while system is online).

    I have a script, called statupdate

    I have located it in /etc/init.d/

    I have given it execute permissions

    I have then put in a link to it under /etc/init.d/RC3.d/S99statupdate

    This worked, but the system boot sequence never finished because the script started kept looping, preventing the system boot sequence to continue.

    I then created another script called startupdate

    that script simply started the main statupdate script. I tried with the following:

    ./statupdate &

    OR

    nohup ./statupdate & 

    I swapped out the S99statupdate with S99startupdate (and gave it execute permissions)

    The exact same issue occured.

    Can anyone point out what I'm doing wrong?

    Cheers,
    Pazu


    this isn't supported first of all..secondly what are you trying to accomplish?
  • The Sophos UTM OS is based on SUSE Enterprise Linux.  On-box documentation and example files are largely absent.

    You may want to look at cron with @reboot in place of, or until, the init side of things are sorted.  There are forum posts that explain how the UTM cron system works (it isn't entirely typical).
  • Thanks TechEd and Barry, I had looked at crontab and @reboot, was hoping to find something that survives a head reset, but I think that is my best option at the moment.

    William - trying to start a script that has a forever loop in it at run time - thats all. I'm aware that this isn't supported, it is a home install.
  • /etc/crontab-static survives most everything.

    Cheers - Bob
  • used crontab and put in an @reboot, now working fine thanks!!