Results 1 to 3 of 3

Thread: Execute a command at system startup

  1. #1
    Join Date
    Sep 2017
    Beans
    1

    Question Execute a command at system startup

    Hello everyone !

    First of all, I know there are many threads on many websites regarding my issue, but despite all of my efforts, I can't get it work... !

    Basically, what I want to do is make a .sh file running when my system boots.

    What I've done so far :

    • I created a new text editor file, typed in
      Code:
      sudo shutdown -r 00:00
      so my computer reboots each day at midnight, and saved this file with the extension .sh on my desktop
    • I moved the file to the /etc/init.d directory using sudo mv command on terminal
    • I did set up executable permission on script with terminal, typing
      Code:
      chmod +x /etc/init.d/script.sh
    • I used the following command to get my file executed at my system startup :
      Code:
      update-rc.d script.sh defaults 100


    Have I done something wrong, or does it miss any step so I can get it work ?

    Hope that anyone could help me on that ! Thank you very much.

    Max

  2. #2
    Join Date
    Apr 2011
    Location
    Mystletainn Kick!
    Beans
    13,614
    Distro
    Ubuntu

    Re: Execute a command at system startup

    Remove the sudo from the command.
    It's not needed in /etc/init.d and most likely is causing the issue since sudo usually needs user interaction.
    You would also most likely need to set the full path to shutdown, /sbin/shutdown should be it.
    Splat Double Splat Triple Splat
    Earn Your Keep
    Don't mind me, I'm only passing through.
    Once in a blue moon, I'm actually helpful
    .

  3. #3
    Join Date
    Nov 2008
    Location
    Boston MetroWest
    Beans
    16,326

    Re: Execute a command at system startup

    A much better way to handle scheduled jobs like this is through cron.

    Code:
    sudo echo '00 00 * * * /sbin/shutdown -r now' >> /var/spool/cron/root
    That will run the command "/sbin/shutdown -r now" every night at midnight.

    See: https://help.ubuntu.com/community/CronHowto
    If you ask for help, do not abandon your request. Please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

Tags for this Thread

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
  •