My sysadmin toolbox

52

Author: Oleg Romanyshyn

I’ve been working as a Linux admin for more than six years, and using Linux for a little longer. Like a lot of Linux administrators, I started with Red Hat, but now I use Debian stable at work and Gentoo at home. Recently, NewsForge asked readers to “let us know about your most valuable utilities.” Here are mine.

Vim

I wouldn’t survive a day without the Vim editor. When you have a new system, the first thing you need is a tool for editing and creating configuration files and such stuff. The more you use Vim, the more features you discover, and the more you get used to its shortcuts and coloring. It would be hard for me to switch to something else now. But since Vim ports exist for virtually every system, you always have the option to install and use it. Learn once, use forever.

man

Manuals are very important, and that brings man to the second spot on my list. Usually you don’t want to go through the complete documentation for a command, you just need a couple parameters for your immediate needs, and you will find such information in man. Eighty percent of the time consulting a man page is enough to resolve my problems. By using man, you can free some room in your brain by purging options and syntax for commands you rarely use.

Midnight Commander

For those of us who came to Linux from MS-DOS and are familiar with Norton Commander, Midnight Commander is a reminder of the past. I can do a lot of things much faster with mc than from the command line — for example, copying files and creating compressed tarballs. Midnight Commander is one of the first programs I install on a new system.

SSH

As everything is connected now, you need something to secure your links to other systems. The best tool you can use for secure connections is Secure Shell (SSH). You can even use this tool for tasks that don’t seem to be doable, like forwarding ports for applications to another host and port, or enabling X11 forwarding.

GNU Screen

If you need to monitor the execution of certain applications, try Screen. You can start a job, then detach it, and see it again when you need it. This can be useful if you want to have access to the job’s status screen from different computers. Screen lets you see a list of running screen processes, kill processes, view the scrollback history for a session, or turn logging on and off.

rsync

The rsync utility is a great tool for synchronizing files. Using rsync you can keep two different systems, or just some parts of systems, synchronized. The best way to do it is to run rsync as a cron job when you are not using your machine, for example at night or on weekends.

Rsynch uses bandwidth efficiently, since it transfers only the differences between two sets of files, and only the parts of each file that have been changed since they were last synchronized. And it can use SSH as a transport so your files are transmitted over an encrypted connection.

Cron

Cron is a utility for automating script and program execution. Using this utility you can schedule regular background jobs for maintenance tasks such as backing up and purging unnecessary stuff.

The Links browser

It’s hard to live without a browser. If you can’t find help in your local man pages, you look for help online. I love Links for this purpose. Links has a more powerful brother, Lynx, but Links was created for monochromatic terminals, which makes it better if you don’t need fancy-shmancy colored text. It’s a great light and stable alternative to the big GUI browsers.

Grep

Grep is a great tool for searching text in files, which, since I program, I do often. If you want to find out whether any files in current directory contain text, you can just fire up grep text * and you’ll get the list of files. You can search subdirectories too with the -R option, although it can take some time.

Compare files with diff

If you need to find differences between two files, you will want to use diff. Running diff -u file1file2 will show you where they differ. It can also be useful for scripting, if you want to send from a remote system just the changes between certain files. To do this, you can create a cron job and pipe out differences to your email.

Many other tools make life easier, such as the file utilities df and du, network tools iptraf and netstat, less for viewing files, Mutt for emailing, and many others.

Let us know about your most valuable utilities (there need not be 10 of them), and if we publish your work, we’ll pay you $100.

Obsessive behavior

I’ve become so interested in which tools I use the most that I tried to find a way to calculate which commands I use. To do that you can use your history file if your shell uses one. I use bash, and my history files reside by default in my home directories on many servers.

Bash’s history file is .bash_history, and by default it contains up to 500 entries. I wanted to have more entries to work with, so I could be more accurate. You can set HISTFILESIZE in the .bashrc to a larger number, so I set mine to 2,000. Then I wrote a script to calculate the tools I use the most.

#!/usr/bin/perl

$stop_iter = 10;
%count = ();

while(<>){
    $first = (split)[0];
    $count{lc $first}++;
}

foreach $word (sort {$count{$b} <=>$count{$a}} keys %count) {
  printf "%5d %sn", $count{$word}, $word;
  last if (--$stop_iter == 0);
}

Save that code to a file called hist_script (or whatever you prefer), make it executable, and fire it up:

./hist_script .bash_history

It will print out the top 10 commands that you use. Change $stop_iter to something else if you want to see more or fewer results. According to the script, the programs that I use most often are:

369 exit
300 su
268 cd
231 fai
212 ls
205 vi
187 ssh
114 cp
112 make
111 mutt

I program on Linux and fai is the UI for my version control system. I was surprised that less didn’t make it into the list, but it’s a sure thing that exit deserves the top spot, I suppose.

It would be extremely interesting to see what other administrators use.

–OR