Applied Laziness, bash functions to make you a better lazier sysadmin

As a good sysadmin, you are probably in the good habit of making a backup copy of critical system files before editing them.

But, as a good sysadmin, you are probably confident enough to occasionally skip the above step.

With a few bash functions and an alias or two stuffed in your .bashrc, doing the right thing can be seamless and alleviate the worry about having to retrieve backup tapes in a timely fashion.

Bash function I use daily.


function back_file
        echo "Working on $1"
        if [ ! -f $1 ];then
                echo "$1 doesn't exist"
        export ndate=`date  +%m-%d-%y-%H:%M`
        echo    cp $1 $1.$ndate
        cp $1 $1.$ndate

Example usage:

paskoblaster:~: $ touch foo
paskoblaster:~: $ back_file foo
Working on foo
cp foo foo.09-21-11-10:42

This alone is a timesaver, but when combined with an another bash function, I get good things for few keystrokes, and an easy back out plan should I fat-finger or typo the change.

function bvi
 if [ ! -f $1 ]
        echo "must enter file to edit"
 back_file $1
 vi $1


with the keystrokes:

bvi foo

The function makes a backup copy, resizes the terminal window and runs vi on the file.

All in all, a huge time saver which supports good sysadmin karma.

Season to taste, your mileage may vary.




This entry was posted in Nerd, Solaris, Uncategorized. Bookmark the permalink.