Update and Shutdown; sudo, halt, stuff like that.
So I sometimes run the script stop.sh to shut down my Debian machine (it lives in ~/bin).
$ stop.sh [sudo] password for username:
It asks me for my root password then does an update to get the new file version information, then an upgrade and then halts the machine. It’s a one-liner:
cat stop.sh #!/bin/bash sudo apt-get update && sudo apt-get -y upgrade && sudo shutdown -h now
Now, what’s bad about this?
- Well, sudo ‘remembers’ that I’ve typed my password for (by default) five (or is it fifteen?) minutes, so if the early steps (update, for example) take a long time, the latter ones won’t work.
- Also, if my intent is to let it update and shut down without me, I’ll be walking away from a machine in which root access is available for that five (or is it fifteen?) minutes, so I probably want to lock the screen before I go. Not a big deal if it’s a home machine or you can lock the office, and probably not a big deal anyway unless you deal with sensitive information (or work with untrustworthy people…).
- The -y flag tells apt-get to say ‘yes’ to any queries the installer might ask. Could be a problem if I have a non-standard install or specific needs.
- I don’t see any information that the installer might give me, and I don’t find out if it worked till I come back and boot up.
- Some packages give information screens and ask the user to input a choice or acknowledge some information. They can mean it does not complete the task and so does not shut down.
The apt-get man page says:
-y, --yes, --assume-yes Automatic yes to prompts; assume "yes" as answer to all prompts and run non-interactively. If an undesirable situation, such as changing a held package, trying to install a unauthenticated package or removing an essential package occurs then apt-get will abort. Configuration Item: APT::Get::Assume-Yes.
So that should be borne in mind too.
Still, I use it anyway.