sandip's blog

Non-desctructive read-write badblocks disk check

Below command can be run on unmounted partitions to do a disk check of badblocks. Use -p if you need to automatically fix issues. Single "c" will only do a badblock read test.

e2fsck -vfcc -C 0 /dev/sdb4

"-C 0" -- displays progress
"v" -- verbose output
"f" -- force check
"cc" -- read-write test

resend all mails in sendmail queue

As root you can redeliver all mail in the mail server queue via:

sendmail -v -q

mismatch_cnt is not 0

Mismatch_cnt (/sys/block/md#/md/mismatch_cnt) is the number of unsynchronized blocks in the raid.

Not much of an issue if this is reported on raid-0 or raid-1 and can be ignored. See bugzilla report: Bug 566828.

The repair is to rebuild the raid:

echo repair >/sys/block/md#/md/sync_action

This does not reset the count, but if you force a check after the rebuild is complete:

echo check >/sys/block/md#/md/sync_action

Count should return to zero. Verify with:

cat /sys/block/md#/md/mismatch_cnt

Upgrade CentOS 5.4 to 5.5 for OpenVZ containers

Edit "/vz/template/centos/5/{ARCH}/config/yum.conf", and change the base and updates repositories as below:

[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

#released updates
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

Do a `vzyum {VEID} clean all`.

List updates:

vzyum {VEID} list updates

Update:

vzyum {VEID} update

Confirm that all VEs' have been updated to 5.5 with:

cat /vz/root/{VEID}/etc/redhat-release

You should see "CentOS release 5.5 (Final)".

Change server timezone

To change the server timezone, just create a link to the respective zone you're on.

ln -sf /usr/share/zoneinfo/US/Eastern /etc/localtime

Check with the `date` command.

lighttpd redirect to external url if file not found

Below is a rewrite/redirect rule using url.rewrite-[repeat]-if-not-file similar to Apaches' "!-f" RewriteRule.

# Redirect to external url if image file not found
url.rewrite-if-not-file = ( "^\/images\/.*\.jpg$"; => "/redirect$0" )
url.redirect = ( "^\/redirect\/(.*)$" => "http://other.domain.tld/$1" )

Deny access to .htaccess files in lighttpd

In lighttpd you can use mod_access to deny files starting with a certain expression, such as hidden dot files. (example: .htaccess or .svn)

# Deny access to hidden files
$HTTP["url"] =~ "/\." {
    url.access-deny = ("")
}

Find files that have not been accessed for a while

Below one liner uses the find command to list files sorted by access time beyond the provided "number of days".

find </path/to/folder> -type f -atime +<number of days> -exec ls -ultr {} \;

This becomes handy if you want to do archive and cleanup of your web folders that have grown to a huge size.

Plesk email users and passwords

Below is sql, if you ever need to test out your users email accounts on plesk server:

mysql> use psa
mysql> select concat(mail_name,"@",name) as email_address, accounts.password from mail left join domains on domains.id=mail.dom_id left join accounts on accounts.id=mail.account_id;

Check for entries in passwd file

Check for entries in passwd file:

getent passwd username >/dev/null 2>&1 && echo "user exists" || echo "user does not exist"

id username >/dev/null 2>&1 && echo "user exists" || echo "user does not exist"

awk -F':' '$1 ~ /^username$/ {print $0}' /etc/passwd  | grep -w username >/dev/null 2>&1 && echo "user exists" || echo "user does not exist"

Comment