abughali.com IT and Business Blog by Mahmoud Abu-Ghali

9Nov/090

Who else is on your server?

Many system administrators use scripts to help them in the process of managing a server. A common problem is finding out exactly what users are on the system and what they are doing.
Several tools are available on the system to see who is online, what processes are running, and pipeing them together can resolve many problems. Here are 2 small scripts that will show, first if a user is online, and then what he is running:

who | grep $1
ps -aux | grep $1

The variable $1 here means the first command line argument, from a shell script. The who command first checks if the user is online, then ps will show all the processes currently running under that user's UID.

Filed under: Unix/Linux No Comments
9Nov/090

Who owns this port

An interesting UNIX command is the fuser program. This program can tell you which user and process owns a port. For example, the following command will tell you who owns port 6000:

fuser -v -n tcp 6000
Filed under: Unix/Linux No Comments
7Nov/090

Don’t grep grep

A useful tool in unix scripting is the "grep" function. This program will find a string in a file. It is often used also to find if a process is running:

ps ax | grep sendmail

That command will find if sendmail is running. The problem is that you might end up with an other entry for this command. Because you grep for "sendmail", you may well end up with this command showing because the "sendmail" string is in the command line. To avoid that, you can use the -v flag to grep:

ps ax | grep sendmail | grep -v grep

That command will find all the lines in the current process list that have the "sendmail" string in it, and will remove the lines containing the string "grep".

Filed under: Unix/Linux No Comments