We have upgraded the community system as part of the upgrade a password reset is required for all users before login in.

Reboot script



  • I am trying to create script to run some cleanup commands before rebooting. I have tried adding:

    @reboot ( sleep 10 ; sh /root/reboot.sh )

    to my root crontab but it is ignored/doesn't run. "sh /root/reboot.sh" runs ok on it's own.

    Please can one of you awesome onioneers suggest another option or help me find the shutdown script? šŸ™‚



  • @reboot ( sleep 10 ; sh /root/reboot.sh )

    This isn't a valid crontab entry, which is why nothing would be happening. I'm hoping you didn't find something online that suggests that as a crontab entry....

    In any event, cron is used to schedule activities at a specific time or interval of time, so unless you want to reboot regularly (e.g. once a day/week/month) it might not be the best choice.

    However, since you mention cron, a valid entry would look like this:

    # m h dom mon dow command
    00 07 * * 1 /bin/sleep 10; /bin/sh /root/reboot.sh
    

    Which would execute your reboot.sh script at 07h00 every Monday.

    Since cron executes in its own shell environment with its own PATH which may not match your path, it's good practice to provide the full path to any programs you plan to execute (e.g. /bin/sh instead of just sh) to ensure that the correct program is executed.



  • @cas There are plenty sites that mention using cron - all have the @reboot directive which is why I tried it and followed their ewxamples. I don't want to run the script at a scheduled time, I want to run it when the onion goes down for reboot...



  • You can put an entry in /etc/rc/local (before the exit 0) which will be run at startup (you might want to background it with & if it will take a while).

    Make sure you fully qualify all paths and remember it's a bad idea to name any scripts the same as commands so call it myreboot.sh



  • @Paul-Cousins

    @cas There are plenty sites that mention using cron - all have the @reboot directive which is why I tried it and followed their ewxamples. I don't want to run the script at a scheduled time, I want to run it when the onion goes down for reboot...

    Well, wouldn't you know, there is such a directive. True saying that, learn something new every day. šŸ˜„

    However, according to the crontab man page, the meaning of @reboot is "Run once, at startup." so you'd still not be achieving your objective.

    What you'll probably need to read up on is OpenWrt Init Scripts, specifically in your case, the section regarding the implementation of the stop() function. The init daemon stop scripts are what are supposed to execute during the orderly shutdown process of a linux system.

    To accommodate a power loss situation, you'd need some additional circuitry to trap that and initiate an orderly shutdown.



  • thank you @austin-Sandford - good advice!
    @cas - looks like i completely misunderstood what I read - thank you for clarity! šŸ™‚ I am looking into the init scripts you suggested - will post later on my progress



  • @austin-Sandford This should be /etc/rc.local

    root@Omega-0E97:~# cat /etc/rc.local
    # Put your custom commands here that should be executed once
    # the system init finished. By default this file does nothing.
    
    exit 0
    root@Omega-0E97:~#
    

Log in to reply
 

Looks like your connection to Community was lost, please wait while we try to reconnect.