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 dist-upgrade, then halts the machine. It’s a one-liner:

cat stop.sh
#!/bin/bash
sudo apt-get update  && sudo apt-get -y upgrade && sudo apt-get -y dist-upgrade && sudo halt

Now, what’s bad about this?

  1. 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.
  2. 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…).
  3. 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.
  4. 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.
  5. 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.

 

Lazy.

Advertisements

Tags: , , , , , , ,

About Darren

I'm a scientist by training, based in Australia.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: