Blogs

Testing zipped archives

If you've got a lot of zip files and need to test it, here's a one liner that can be used to quickly validate the archives:

for x in `ls` ; do zip -T $x ; done | tee /tmp/archive_test.log

comparing files line by line

Here's a way to compare two files that have common lines in both files:

sort file1.txt > file1_sorted.txt
sort file2.txt > file2_sorted.txt
comm -12 file1_sorted.txt file2_sorted.txt

Note: files need to be sorted first prior to comparing.

cofigure phplist spellcheck for firefox

PHPList comes with FCKeditor as the gui default editor. However, by default it is setup so that the spellcheck is only available to IE users. To enable for other browsers such as Firefox, follow the below directions:

  1. Edit admin/fckphplist.php:
  2. Replace all instances of:
    FCKConfig.SpellChecker      = 'ieSpell' ;

    with:

    FCKConfig.SpellChecker      = 'SpellerPages' ;

  3. Edit admin/.htaccess and add "spellchecker.php" to the list of files to allow access to.
  4. If this is a linux box, then make sure aspell is installed. Edit "admin/FCKeditor/editor/dialog/fck_spellerpages/spellerpages/server-scripts/spellchecker.php" and update the aspell program path:

    $aspell_prog    = '/usr/bin/aspell';

That should do it.

Pictures from the Computer History Museum

Here's a set of photos I took at the Computer History Museum. If you like switches and indicator lamps you will love these pics.

Not strictly linux-related I know but the Linux lineage can be traced back to many of these systems!

Some samples after the break.

Backup, restore and cloning of partition table

To backup partition table:

sfdisk -d /dev/sda > sda.table

To restore the partition table:

sfdisk /dev/sda < sda.table

To clone partition table:

sfdisk -d /dev/sda | sfdisk /dev/sdb

set_loginuid failed opening loginuid

If this file doesn't exist:

/proc/<pid of crond>/loginuid

It's because the kernel doesn't have AUDIT enabled. So you get a bunch of errors in "/var/log/secure" with "set_loginuid failed opening loginuid".

Recompile kernel with audit support:

CONFIG_AUDIT=y
CONFIG_AUDITSYSCALL=y

If recompiling of kernel is not an option then:

Comment the below lines from all pam.d files.

session required   &nbsp;    pam_loginuid.so

Find files via:

# grep -l pam_loginuid.so /etc/pam.d/*
/etc/pam.d/atd
/etc/pam.d/crond
/etc/pam.d/login
/etc/pam.d/remote
/etc/pam.d/sshd

Loss in network connectivity on OpenVZ host

I was seeing loss in network connectivity when an OpenVZ container is stopped and noticed that the bridge mac address was taking the mac address of an existing containers virtual network interface instead of the physical interface.

The solution was to set the bridge mac address to the physical interface:

/sbin/ifconfig br0 hw ether $(ifconfig eth0 | awk '{print $5; exit}')

Here is what my "/etc/sysconfig/vz-scripts/vps.umount" looks like which is used to remove routes to container with veth-bridge from bridge.

Weekly backups of all OpenVZ container

Here's is a simple shell script to run a weekly lvm snapshot dump of all OpenVZ containers using the vzdump utility:

#!/bin/bash
# ve_dumps.sh
# Dump all VEs

# Todays' date
DATE=$(date +%d)

# Paths
BAK_PATH=/opt/bak/vz_dumpsr /># Week of month
BAK_DIR=$(cal | awk -v date="${DATE}" '{ for( i=1; i <= NF ; i++ ) if ($i==date) { print FNR-2 } }')

# Function to check and remove previously failed snapshot.
check_vzsnap() {
  OUTPUT=`/usr/sbin/lvdisplay | grep vzsnap`
  [ -n "$OUTPUT" ] && lvremove -f /dev/vg0/vzsnap
}

# Function to perform backup.
backup() {
  # Check and create the required backup directory
  [ -d "${BAK_PATH}/${BAK_DIR}&quot; ] || mkdir -p ${BAK_PATH}/${BAK_DIR}
  # do dumps
  echo "Starting dump at `date`"
  /usr/bin/vzdump --exclude-path '.+/log/.+' --exclude-path '.+/bak/.+' --exclude-path '/tmp/.+' --exclude-path '/var/tmp/.+' --exclude-path '/var/run/.+pid' --snapshot --dumpdir=${BAK_PATH}/${BAK_DIR} --compress --all
  echo "Completed dump at `date`"
}

# Main ############################r />
# Remove previously failed snapshot
check_vzsnap

# Run backups
backup

exit 0

Week of Month

Here is a simple one liner to get the week of month via awk from a `cal` output:

$ cal | awk -v date="`date +%d`" '{ for( i=1; i <= NF ; i++ ) if ($i==date) { print FNR-2} }'

Verifying SSH Key Fingerprint

If you've been given a public ssh host key and want to verify it before adding it permanently to your ssh known_hosts file:

Get the public ssh key:

$ ssh-keyscan -p 22 -t rsa,dsa {remote_host} > /tmp/ssh_host_rsa_dsa_key.pub

Get the ssh key fingerprint:

$ ssh-keygen -l -f /tmp/ssh_host_rsa_dsa_key.pub

Comment