4

I frequently (all day every day) have a minicom terminal tab open and execute commands on an embedded Linux system from my Ubuntu laptop. Sometimes I have to execute the reboot command, and sometimes, I am ashamed to admit, I accidentally execute reboot in the wrong tab and my laptop does exactly what it was designed to do without asking any questions...

I am using Ubuntu 16.04 LTS and tried installing molly-guard but that has had no effect.

99 times out of 100 I don't mess up but my laptop takes a good 10 minutes to reboot and I execute reboot frequently enough for this to be an annoyance.

Is there some bit of black magic, I can add to my custom terminal window setup bash script, that will make reboot map to something else (just for that bash session preferably)?

  • 7
    How about white magic, such as the incantation of not sitting at a superuser-privileged prompt so frequently an errant reboot will hose your workstation. – DopeGhoti Feb 23 '18 at 22:03
  • 1
    Maybe next time I reinstall my OS... Right now all my paths are pretty much reliant on me being root and I am too lazy to fix them. Also there is the horror of having to type 5 extra characters for every other command... Nah defiantly better to spend my time making obscure workarounds and hacks to keep from messing up. :-) – Nathan Owen Feb 23 '18 at 22:28
  • That molly-guard isn't working is interesting, since it also implements a safeguard in a similar fashion to other solutions (/usr/sbin/reboot to take over /sbin/reboot). You mention a custom window setup function, does that muck with PATH already? – robbat2 Feb 23 '18 at 23:16
  • @DopeGhoti Won't necessarily fix things. If you're running a systemd using Linux (which Ubuntu 16.04 is) users who are the only ones logged into the system can restart the machine without elevating privileges (i.e. without sudo/su/logging in as root). I believe there's settings to control this behavior, but many of the single-user-oriented distros (like Ubuntu) turn it on by default. – R.M. Feb 23 '18 at 23:33
  • @robbat2 Nope. Here is my path (it matches the one in ~/.bashrc): /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin – Nathan Owen Feb 24 '18 at 0:06
11

In the ~/.bashrc file on your laptop (not on the embedded machine), add the line:

reboot() { echo  "Hey, don't do that!"; }

If you actually wanted to run reboot on the laptop, you can get around this function by running sudo reboot or /sbin/reboot.


Or, you could make it more friendly, as man0v suggested, by using:

reboot () { echo 'Reboot? (y/n)' && read x && [[ "$x" == "y" ]] && /sbin/reboot; }

I suggest putting such a function in ~/.bashrc because we want it available in interactive bash sessions.

  • 3
    or you could have reboot () { echo 'Reboot? (y/n)' && read x && [[ "$x" == "y" ]] && /sbin/reboot } – man0v Feb 23 '18 at 22:07
  • That is probably a better solution than the one I came up with, since mine involves modifying $PATH. – Nathan Owen Feb 23 '18 at 22:09
-2

Okay, after playing around a bit more I found an okay solution:

I created a bash file named 'reboot' in /usr/sbin/ and then added the complete path /usr/sbin/reboot to the front of $PATH.

Here is the script:

read -p "Are you sure? " -n 1 -r
echo    
if [[ $REPLY =~ ^[Yy]$ ]]
then
    /sbin/reboot
fi

Maybe not the best solution though...

  • 2
    Very good. One potential issue is that changing the system file /usr/sbin/reboot may cause problems with system utilities as well as X11/GUI programs that depend on the default behavior of /usr/sbin/reboot. – John1024 Feb 23 '18 at 22:09
  • It also is still letting you keep your nasty habit of leaving superuser prompts open for errant reboot commands. – DopeGhoti Feb 23 '18 at 22:10
  • Actually I found I did not even have to type sudo for the reboot command to work, not sure why. Not like I don't leave super user terminals open all the time anyway. I mostly remember to lock my computer before walking away... mostly. :-) – Nathan Owen Feb 23 '18 at 22:13
  • @John1024 no system utilities depend on /usr/sbin/reboot, since there's no such file in a stock system. The stock reboot binary is in /sbin. – Ruslan Feb 24 '18 at 6:27
  • -1 because: you shall not edit stuff in /usr/sbin – Kamil Nov 28 '18 at 21:19

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.