August 2025
M T W T F S S
 123
45678910
11121314151617
18192021222324
25262728293031

Categories

August 2025
M T W T F S S
 123
45678910
11121314151617
18192021222324
25262728293031

sed one liners

sed one liners
Insert character at beginning of line

Example: comment out all nfs entries in /etc/fstab

sed -i ‘/nfs/s/^/#/’ /etc/fstab

Uncomment out all nfs entries in /etc/fstab

sed -i ‘/nfs/s/^#//g’ /etc/fstab

Make a copy of a file, then substitue a string in the original

perl -i.orig2 -p -e ‘s/10.49.5.61/10.49.5.62/g’ /etc/fstab

Print contents of a file between lines 1 and 609

sed -n ‘1,609’p /var/log/tspulsemail.log > index.html

EXT3-fs warning Directory index full!

At times, I come across the following message in syslog:
kernel: EXT3-fs warning (device dm-3): ext3_dx_add_entry: Directory index full!

On systems in which this is being constantly logged to syslog, this can become rather annoying, but it is not a bug. It’s informing the user that somewhere within the system, a directory has more than 32,000 subdirectories. A directory can have at most 31998 subdirectories, because an inode can have at most 32000 links. (See external link below for source)

Sometimes, this can be difficult to find, especially in a case whereby a physical server is hosting a couple of hundres VPS accounts. To help break down where the culprit(s) is coming from, I’ve put together this quick script to tell me where to start looking:

#!/bin/bash
# Kristian Reese
# http://kb.kristianreese.com

for veid in $(vzlist -aHh 0*.tld.com -o veid)
do
echo $veid
vzctl exec $veid ‘find /var -type d 2>/dev/null |

(
while read dir; do cnt=`ls -l “$dir” | wc -l`

if [ “$cnt” -gt “10000” ]; then
echo “$cnt: $dir”
fi

done
)’

echo
done
Most of the time, customer emails are queued up in their qmail mailboxes. I’ll investigate to see what these emails are. For example, in one particular case, I found the customer was running a cronjob to check the status of httpd every waking moment of uptime. The crontab did not output to /dev/null, and therefore emails were being sent each and everytime the crontjob ran. This script was named “keep-apache-alive” and was subjected as such in the emails, so I looked to see how many of these there were in the users /var/qmail/mailnames/domain.com/info/Maildir/new. There were a LOT, so I blew them away and fixed cron to output to /dev/null, preventing the cronjob from sending emails.

-bash-3.1# find . -type f -exec cat {} \; | grep “keep-apache-alive” | wc -l
-bash-3.1# find . -type f -exec grep -q “keep-apache-alive” {} \; -exec rm {} \; -exec echo removed {} \;
-bash-3.1# find . -type f -exec cat {} \; | grep Subject | more

Another method would be to use the following bit of perl code:

#!/usr/bin/perl
use File::Find;
my %dirs = ();
find
(
sub
{
unless(-d $_) { $dirs{$File::Find::dir}++; }
}, ‘.’
);

foreach(keys %dirs) {
if ($dirs{$_} > 20000) {
print “$_ has $dirs{$_} files.\n”;
}
}

How To create a local mirror of latest Red Hat Enterprise Linux without using Satellite server

How To create your own local Red Hat Enterprise Linux yum repository server

To begin, build a virutal machine or stand alone system installing the same OS version of Red Hat you wish to serve as the yum repository. At the time of this writing, my base OS plus mirror data consumed 14G of disk space so be sure to size your disk appropriately. This is necessary as you must register the mirror server to a RHN Satellite, which allows the system to receive software updates. It’s also important to know that one physical system cannot subscribe to multiple architecture base channels. In otherwords, if you install a 64-bit OS, you cannot subscribe to the 32-bit channel.

After the system has been deployed, you’re ready to begin:

Register with RHN
~# rhn_register -vv –nox
Install required packaged
~# yum install createrepo
~# yum install yum-utils
Create a directory for the repo and sync the base channel
~# mkdir /opt/rhel6repo
~# reposync –gpgcheck -l –repoid=rhel-x86_64-server-6 –download_path=/opt/rhel6repo
Note: This will take a long time to run. I ran mine overnight
Create repo data
~# createrepo /opt/rhel6repo
Configure apache to serve the content:
~# vi /etc/httpd/conf.d/rhel-6-repo.conf

Alias /rhel-6-repo /opt/rhel6repo


Options Indexes MultiViews FollowSymLinks
Order allow,deny
Allow from all

Start/restart apache
~# service httpd start

Next, configure the clients by adding the repo to the yum config:

~# cat /etc/yum.repos.d/rhel6.repo
[rhel-6-repo]
name=My Red Hat Enterprise Linux $releasever – $basearch
baseurl=http:///rhel-6-repo
enabled=1
gpgcheck=0

From the client, verify it can see the mirror with yum repolist

You can disable connectivity to Red Hat network by changing the value of enabled = 0 in the file /etc/yum/pluginconf.d/rhnplugin.conf

Clean out the yum cache and remove old header info on the client.

~# yum clean all

Now, you can list all of the updates available from your local mirror.

~# yum list updates

How to find dead links and delete them

Sometimes, after performing VPS migrations, the soft links in /etc/vz/conf may not be removed. Over time, the dead links may build up and cause many ‘No such file or directory’ messages when trying to look for common settings amonst all conf files (ie cat /etc/vz/conf/*.conf | grep whatever).
Quick easy way to delete these dead links:

~# cd /etc/vz/conf
~# for f in `find . -type l ! -exec test -r {} \; -print`; do rm -f $f; done

One liner:

~# find -L -type l -exec rm -f {} \;
* Please test before issuing these commands on production systems!!

udev assigns incorrect number to eth device

eth interface number changes and is not what is expected

During a recent exercise where I created a RedHat 6.3 virtual machine, clones of that virtual machine each had different numbers assigned to their respective eth device(s). I’ve run into this booger before in the past and remembered that udev creates a persistent rule in /etc/udev/rules.d that needs to be modified to obtain the desired NIC layout. The file is:

/etc/udev/rules.d/70-persistent-net.rules

After modifying that file to match MAC address to eth0, eth1, eth{N}, reboot.

Otherwise, if you’re not comfortable with editing the file or are unsure which MAC is suppose to be which eth device, simply remove the file and reboot. udev will recreate it on boot up.

passwd: Authentication token manipulation error

Check if /etc/shadow exists. If it doesn’t, run the command ‘pwconv’ then try changing the user password again.

How to check if Large File Size (LFS) is enabled

To check if a file system supports the LFS standard, you can use the getconf command. If the result is 64, LFS is supported.
getconf FILESIZEBITS /

In the example above, the root file system was checked. If /var for example, is a separate file system, specify /var in its place. You may also use the ‘mount’ command to verify the file system type that is being used. ext2 / ext3, for example, has full support for LFS.

I found this nice read take from suse.de

Kernel 2.6: For both 32-bit systems with option CONFIG_LBD set and for 64-bit systems: The size of a file system is limited to 273 (far too much for today). On 32-bit systems (without CONFIG_LBD set) the size of a file is limited to 2 TiB. Note that not all filesystems and hardware drivers might handle such large filesystems.

How to disable cron based mail alerts

How to disable cron based mail alerts
The easiest way to disable cron based email alerts is to append the following to the specified command within the users crontab:

>/dev/null 2>&1

Example:

# m h dom mon dow command
59 23 * * * /root/scripts/hotfixes/vzagentdb.sh >/dev/null 2>&1
CRONDARGS=’-m off’ in /etc/sysconfig/crond may also be specified to turn off mail completely. Other postings have also indicated setting the MAILTO=”” option in the users crontab also works.

Note that I’ve seen cases where the qmail queue was so high that even after implementing these measures, it seemed to not work, but that was because the qmail queue was draining. Once it completely drained, the madness stopped.

Create a temp file with random characters

tmpfile=`/bin/mktemp /var/log/rpmpkgs.XXXXXXXXX` || exit 1

System hangs during messagebus startup

System hangs during messagebus startup
This problem has been experienced after rebooting a system in which ldap has been configured. Note that LDAP functions properly immeidately after it is setup on the machine, but hangs at “staring system message bus” after a reboot. To fix, reboot in single user mode or into linux rescue and edit /etc/ldap.conf

If linux rescue is used, the disk may have to be remounted rw in order to edit /etc/ldap.conf if for some reason a user receives a read-only file system message or cannot chroot to /mnt/sysimage.

edit entry with following content:

nss_initgroups_ignoreusers root,ldap,named,avahi,haldaemon,dbus