13.07.2015 Views

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 1 ■ SAVING YOURSELF EFFORT01 shopt -s histappend02 PROMPT_COMMAND='history -n;history -a'03 HISTSIZE=10000004 HISTFILESIZE=100000Line 01 fixes the problem whereby if you have multiple terminals open, information may be lost.This happens because the default bash behavior is to overwrite the history across sessions, rather than toappend.Line 02 extends this to give you real-time appending to history across multiple terminals. ThePROMPT_COMMAND setting executes the given command at every prompt; here it means that the shell writesto the history and then reads the history file every time you hit Enter. (The default behavior is that you’llget the history from a given terminal written to file only when you close that terminal.) Bear in mind thatthis means that when you go back through your history (with the up arrow or with a shortcut such as !!),you’ll be accessing whatever your last command on that machine was, not just your last command inthat terminal window.Lines 03 and 04 extend the history past the 500-command default. These 500 commands comearound pretty quickly, and with that as a limit, you’re highly likely to lose information you want to keep.You can increase these numbers if you want.Finally, line 05 prefaces each line of the history file with a timestamp in the format 2009-03-0810:54:31.If things get really chaotic and you don’t want to go hunting through your ~/.bash_history, try thefollowing find command to find any file that has been modified in the last ten minutes:find / -fstype local -mtime -10mNote that you’ll need to run this as root (or use sudo) to avoid getting lots of error messages, becauseit searches from /. It will also take a long time on any machine with large filesystems: looking through~/.bash_history will be faster, especially if you’ve used the previous recipe to make sure that your~/.bash_history file is up-to-date in real time! -fstype local searches only directories mounted on thecurrent system so will exclude NFS-mounted filesystems. For more information on find, see Chapter 8.All the previous comments about keeping careful track of commands become twice as important whenyou’re installing something. In that case, not only do you want to be able to repeat them if need be, butyou might also want to be able to automate the commands, which requires even more accuracy. SeeChapter 2 for hacks for, and more information on, centralizing and automating installs.1-3. Documentation: Using a WikiSo, you’ve improved your ability to keep track of what you’re doing while you’re doing it; what aboutdocumenting it properly afterward? This is the second part of the documentation problem.A wiki is arguably the best solution—something like MediaWiki (there are plenty other options if youprefer those) is free (in both the speech and beer senses), works well, and is easy to install. See recipe 1-4for how to run multiple wikis on the same base installation.A wiki is also handy if two (or more) sysadmins are working together. If this is the case, it’s probablyworth taking turns to cast an eye over it every week to do any necessary tidying or rearranging. (This isan example of preemptive laziness: it’s worth a small investment of time and effort up front to keep thetool working well so that you don’t waste time and energy when you really need it.) If it’s just you, thismay seem less necessary (since it’ll probably reflect your brain and its organization fairly well), but it’sworth bearing in mind that there may come a time when you have to pass it onto a successor or to2Download at WoweBook.Com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!