Page 1 of 3 123 LastLast
Results 1 to 10 of 23

Thread: Automate a script to start on reboot ?

  1. #1
    Join Date
    Sep 2015
    Beans
    132

    Automate a script to start on reboot ?

    Hi, i have a ubuntu server and I have a script in it at /usr/softwareWhenever the server reboots, I have to goto the above path and then manually start this command every time ./ooklaserver.sh start

    is there a way I can automate this process, so this automatically works ?

  2. #2
    Join Date
    Sep 2006
    Beans
    8,627
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Automate a script to start on reboot ?

    If you want it to run as root, just add it to /etc/rc.local right before the line "exit 0"
    If you want it to run as a particular user, then precede it with sudo

    Code:
    sudo -i -u soamz /usr/software/somescript
    However, that way it will run when the machine itself boots, not necessarily when a user has logged in or anything like that. Nor can that method be used to launch a graphical program.

  3. #3
    Join Date
    Sep 2015
    Beans
    132

    Re: Automate a script to start on reboot ?

    yes, I need it to auto run, when the machine boots due to power failure.
    So, the above works ?

  4. #4
    Join Date
    Sep 2006
    Beans
    8,627
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Automate a script to start on reboot ?

    Yes, it is one method that works. Another is to use a cron job with the @reboot shortcut.

  5. #5
    Join Date
    Sep 2015
    Beans
    132

    Re: Automate a script to start on reboot ?

    Okay added this,
    sudo -i -u soamz /usr/software/./ooklaserver.sh start

    Im on Mac terminal.
    Did vi /etc/rc.local , but the esc doesnt save the file.
    Last edited by howefield; November 29th, 2015 at 12:01 PM.

  6. #6
    Join Date
    Jul 2013
    Location
    Wisconsin
    Beans
    4,952

    Re: Automate a script to start on reboot ?

    Quote Originally Posted by soamz View Post
    Did vi /etc/rc.local , but the esc doesnt save the file.
    That's right, <esc> doesn't do that in vi.
    See http://www.colorado.edu/oit/services...de/vi-commands
    Look under 'file management commands'

  7. #7
    Join Date
    Sep 2015
    Beans
    132

    Re: Automate a script to start on reboot ?

    ALL DONE.
    But the script wont start automatically.
    I had to manually type it in.

    I asked a friend and he said have to do cron.
    So, whats the command to run the cron for this script ?

    sudo -i -u soamz /usr/software/./ooklaserver.sh start
    Last edited by howefield; November 29th, 2015 at 12:00 PM.

  8. #8
    Join Date
    Jul 2013
    Location
    Wisconsin
    Beans
    4,952

    Re: Automate a script to start on reboot ?

    Quote Originally Posted by soamz View Post
    I asked a friend and he said have to do cron.
    I'm sure your friend is a nice person, but I think that's bad advice.

    The reason for failure is important now.
    Maybe your script relies upon environment variables that are unavailable.
    Maybe your script relies upon services that aren't up yet.
    Maybe your script is working just fine, but sending your output to /dev/null.
    Maybe lots of possible causes.
    If your job fails under rc.local, it may (or may not) fail under cron, too.

    There are many ways to run a job at startup before login, or after login, or pretty much any other time you choose.
    rc.local is one, and it works very well.
    cron is another, and it also works very well.

  9. #9
    Join Date
    Sep 2015
    Beans
    132

    Re: Automate a script to start on reboot ?

    Okay since rc.local has failed.
    What shall I do now ?

  10. #10
    Join Date
    Sep 2006
    Beans
    8,627
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Automate a script to start on reboot ?

    By what symptoms does it show that it has failed to run?

Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •