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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 1 ■ SAVING YOURSELF EFFORTmy $debug = 1; # set to 0 to turn off debug outputprint "At step 1\n" if $debug;This may seem like too much hassle for a quick-fix script—I admit I don’t always bother myself. Butyou will be very grateful to yourself in three months’ time if you do it. To make it easier, set up an alias inyour editor to insert if $debug;. For vim, add this line to your .vimrc:iab db if $debug;For emacs, type $debug in an open document, and then type C-u 2 C-x a g db (this adds the wordbefore the cursor as a global abbreviation). You’ll also need to type M-x abbrev-mode to turn on abbrevmode.Then, in whichever of vim or emacs you’ve set up, when you’re editing your Perl script and want totype a print line, type db (then hit Enter) at the end of it. Thus, the following:print "Reached point 3",db;will be expanded to this:print "Reached point 3" if $debug;A mere two keystrokes generates a massive timesaving later when you don’t have to either reinsertall your debug output or go looking for comments.1-8. Version Control: Using Subversion AliasesIt’s a good idea to keep more or less every file you touch in version control. For config files, you maywant to tie this in with your centralization setup (see Chapter 2). On a smaller level, you can use aversion control system for your own scripts, notes, and documents. Using version control, if you makean edit to a file and then realize that you deleted stuff you wanted to keep, you can still get it back! (Thishappened to me recently—I accidentally erased 50 percent of a nearly complete 4,000-word article anddidn’t realize until I went to finish it. I retrieved the previous version from Subversion, and that oneincident has more than made up for any minor time impact that using version control has day to day.)But, being lazy means trying to reduce that minor time impact still further. If nothing else, the easieryou make this for yourself, the more likely you are to use it regularly, which is what you need in order tomake it useful. The following applies to Subversion, which works in much the same way as CVS but withsome of the more irritating aspects of CVS removed. The excellent online documentation should get youstarted if you aren’t already familiar with it; I’m not going to go into the basics of using Subversion here.Here are a couple of aliases to reduce your typing. Add this to your .bashrc file:alias sva='svn add'alias svc='svn commit -m'alias svs='svn status'The first two aliases both need an argument after them.sva file.txt will schedule file.txt to be added to the repository.svc "Commit message" will commit with the given message.10Download at WoweBook.Com

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

Saved successfully!

Ooh no, something went wrong!