Sunday, November 25, 2007

When YUM goes bad...

Ever do a 'yum update' from the command line, then after downloading the packages and starting the update it begins to throw errors at you? I have found that this usually means there is something wrong with the cache or the rpm database. The way I have learned to fix this error is simple, just remove the cache and then rebuild the rpm database as root, like this...

rm -rf /var/cache/yum

rpm --rebuilddb

Once those two commands finish, simply run 'yum update' again and things should be working normally.Good luck!


Friday, November 16, 2007

Restoring a frozen ssh session

If you have ever been logged into an ssh session and had your connection burp and freeze your ssh session, here's a way to get it back without closing the session and opening a new one. Try the following key combination to bring back your locked up ssh session...

ENTER ~ .

(enter key,then shift ~, then period)

This should bring back your ssh session if connectivity comes back. Also, if you were using 'screen' during your ssh session, it would be like you never left and you would be exactly where you were before it locked up :)

Wednesday, November 14, 2007

Which network interface is which?

Servers typically have more than one network interface card. In fact, at my company most linux servers have 5 cards. Just the other day we had to troubleshoot network connectivity with a box that we could not get back up on the network. To make matters worse, we had no idea which physical interface was which. This is where 'ethtool' is your best friend. All we did was run the command below and we could see which physical card was giving us the problem.

ethtool -p eth2 5

The result of this command will blink the light on the network card eth2 for 5 seconds. Of course you can set whatever number of seconds you like. Next time you're not sure which card is which, fire up good 'ol ethtool.

Tuesday, November 13, 2007

Keeping separate history files for users who su to root

THIS IS NOT INTENDED TO BE USED AS A SECURITY SOLUTION.
If you're like me and work for a company who has many linux admins all logging into servers and then su'ing to root, you may find this tip beneficial. It is simply 3 lines that you add to root's .bash_profile which will keep separate history files for each admin that su's to root and the commands they ran. It will allow you to go back and see what the user did as root. Granted the user could delete the history file, but we are only interested in keeping separate history files and going back to review if necessary. You may need to implement a policy or have an agreement with the admins which states no one will delete the history files.

So if you're ready to try this out, fire up vi and add the below lines to root's .bash_profile

export HISTSIZE=3000
export HISTFILESIZE=5000
export HISTFILE=/root/.bash_hist-$(who am i | awk '{print $1}';exit)

Save the file and you're good to go. Now when an admin logs in, su's to root and logs out; a hidden file will be created in the root directory called .bash_hist-userid

Here's an example:

If user jsmith logged in and then su'd to root, you would see a file called .bash_hist-jsmith in the root home directory after the user logs out. Hope this helps :)

This tip is courtesy of my senior admin Steve V.

Have fun!

How to 'grep' in color

Have you ever had to grep for words in a log file or document and wish they jumped out at you? Well here's a real easy way to accomplish this by using alias.

Modify the .bashrc file in your home directory by adding the following line:


alias grep='grep --color=auto'


Save the file and log out and back in again. If you don't want to logout just type the above on the command line and hit enter. Now grep a log file for a keyword and see what comes back! Here's what I get when I grep on .i386 in the /var/log/messages file


[root@testbox ~]# cat /var/log/messages|grep i386

Nov 13 07:07:54 testbox yum: Updated: gnome-python2-extras - 2.19.1-10.fc8.i386
Nov 13 07:08:01 testbox yum: Updated: elfutils-libelf - 0.131-1.fc8.i386
Nov 13 07:08:03 testbox yum: Updated: link-grammar - 4.2.5-1.fc8.i386
Nov 13 07:08:27 testbox yum: Updated: tomboy - 0.8.1-3.fc8.i386
Nov 13 07:08:28 testbox yum: Updated: gnome-python2-libegg - 2.19.1-10.fc8.i386