GBS Technology Blog

Various nuggets of useful technical information.

Monday, July 14, 2008

Vacuuming Databases in Postgres 8.2

Vacuuming makes the databases perform faster.

Run this command to vacuum:
vacuumdb --analyze --verbose -d [database_name]


Sunday, July 6, 2008

Disabling/Removing persistent Lexmark Print Spooler

Click on Start --> Right Click on My Computer and choose manage --> services and applications --> services.

Scroll down and make sure you disable the lexbce server and the print spooler.
Once your done, click OK through it all.
Click on the Start --> Run.
Copy and paste his string:
sc config spooler depend=RPCSS

Click run.

This will disable the lexbce problem and start your print spooler.



Friday, June 27, 2008

Installing Openswan on Redhat 9.0

Openswan 2.x is not compatible with RedHat 9.0 for which OpenSwan 1.0.3 must be used.

INSTALL OPENSWAN FOR REDHAT 9.0:

Check if OpenSwan is installed:

ipsec --version

GBS uses the latest OpenSwan available for RedHat 9.0. At the time of writing that was OpenSwan 1.0.3.
Openswan 1.0.3 installs on Redhat 9.0 and is compatible with any OpenSwan installation. However it needs a special kernel patch that must be installed separately. Either download the Openswan 1.0.3.rpm from www.openswan.org or use:
yum install openswan

If downloading manually, install as follows:
rpm -ivh openswan-1.0.3-3.i386.rpm

Either obtain the kernel patches locally or download them from www.openswan.org:

wget http://www.openswan.org/download/binaries/redhat/9/i386/RPMS/i386/kernel-source-
2.4.20-30.9.openswan_1.0.3_1.i386.rpm
wget http://www.openswan.org/download/binaries/redhat/9/i386/RPMS/i386/kernel-doc-
2.4.20-30.9.openswan_1.0.3_1.i386.rpm
wget http://www.openswan.org/download/binaries/redhat/9/i386/RPMS/i386/kernel-2.4.20-
30.9.openswan_1.0.3_1.i386.rpm

Install as follows:

rpm -ivh --nodeps --force kernel-2.4.20-30.9.openswan_1.0.3_1.i386.rpm
rpm -ivh --nodeps --force kernel-source-2.4.20-30.9.openswan_1.0.3_1.i386.rpm
rpm -ivh --nodeps --force kernel-doc-2.4.20-30.9.openswan_1.0.3_1.i386.rpm

Reboot the server:

reboot

Since a new kernel has been installed, you must change the boot kernel in /etc/grub.conf. Edit
/etc/grub.conf so that the default= for new kernel. In the example below, the new openswan patched kernel is the first one, so default=0, if it was the second one, default=1 and so on.

default=0
timeout=10
splashimage=(hd0,1)/grub/splash.xpm.gz
title Red Hat Linux (2.4.20-30.9.openswan_1.0.3_1)
root (hd0,1)
kernel /vmlinuz-2.4.20-30.9.openswan_1.0.3_1 ro root=/dev/md1
initrd /initrd-2.4.20-30.9.openswan_1.0.3_1.img
title Red Hat Linux (2.4.20-31.9smp)
root (hd0,1)
kernel /vmlinuz-2.4.20-31.9smp ro root=/dev/md1
initrd /initrd-2.4.20-31.9smp.img
title Red Hat Linux (2.4.20-31.9)
root (hd0,1)
kernel /vmlinuz-2.4.20-31.9 ro root=/dev/md1
initrd /initrd-2.4.20-31.9.img




Outlook PST Files Location

Windows 2000 and Office 2000 onwards:

C:\Documents and Settings\username\Local Settings\Application Data\Microsoft\Outlook


Adding Swap partitions on Fedora Core

Physically install the disk.

Locate it in /dev

If IDE it should be detected as hdX
If SCSI or SATA it should be detected as sdX

Use fdisk to partition it

fdisk /dev/device_name

n - for new partition
p - for primary partition
1 - for partition number
Specify start and end cylinders or sizes

t - for type change
L - to list types
82 - for Linux Swap - verify by looking at list when listed

w to writeout to disk and save the partition table.

So, the new partition will be /dev/device_name1

Once the drive has been partitioned above, run:
mkswap /dev/device_name1

Test it by switching it on:
swapon /dev/device_name1

.. and then running top to see it being added to the swap memory size:
top - 16:33:31 up 111 days, 21:59, 1 user, load average: 0.00, 0.00, 0.00
Tasks: 136 total, 1 running, 134 sleeping, 0 stopped, 1 zombie
Cpu(s): 0.0%us, 0.1%sy, 0.2%ni, 99.6%id, 0.1%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 2006264k total, 1990932k used, 15332k free, 230972k buffers
Swap: 2096376k total, 144k used, 2096232k free, 1602840k cached


Add it to /etc/fstab by adding a line as follows specifying it is a swap partition:
/dev/sda2 swap swap defaults 0 0


Reboot when done.


Thursday, June 26, 2008

Finding out who's infected on a LAN

I refer to this excellent article at the Everything Sysadmin Blog:

http://everythingsysadmin.com/archives/000054.html

He uses a nifty little shell command to collect useful statistics from tcpdump and explains the whole process very very well.

In essence, infected computers (by virii or mal/spyware) typically send out tonnes of address resolution requests that flood the network. These request are in the form of ARP packets (ARP = Address Resolution Protocol). By sniffing the network for these packets, one can easily tell which machine(s) are infected.

The command in question is:

tcpdump -l -n arp | egrep 'arp who-has' | head -100 | awk '{ print $NF }' |sort | uniq -c | sort -n

See above for an explanation of how he got to that stage =)


Obtaining machine name to IP mappings from DHCP Server on Linux

Say you're running dhcpd on Linux.

Need to know what IP a certain machine has gotten (and you don't have access to that machine?)
or
Need to know what machine a given IP belongs to ?

One needs to look in the following file:
/var/lib/dhcpd/dhcpd.leases

Since, this file contains all the mappings and lease times handed out (and a lot of redundant information), you may want to grep the file for the information you need. On top of that the information you need may be located several lines away from your search string, so look at the man page for grep for added functionality.

I use the following simple scripts:

To find the IP from the netbios name/machine name:
see_ip [netbios_name]

#!/bin/bash

# Automates display of machines' DHCP IP on LINUX
# Shows machine name and IP in one go from dhcpd.leases file

# Show the machine in /var/lib/dhcpd/dhcpd.leases
# Since the machine name is the 8th line in a stack of info about it
# Display the preceding 7 lines as well
echo "Machine details in DHCP database:"
cat /var/lib/dhcpd/dhcpd.leases | grep -B 7 $1


To find the netbios name/machine name from the IP address:
see_netbios [ip_address]

#!/bin/bash

# Automates display of DHCP IP's machine name on LINUX
# Shows machine name and IP in one go from dhcpd.leases file

# Show the machine in /var/lib/dhcpd/dhcpd.leases
# Since the IP is the 1st line of 8 in a stack of info about it
# Display the following 7 lines as well
echo "IP details in DHCP database:"
cat /var/lib/dhcpd/dhcpd.leases | grep -A 7 $1



Switching off roaming profiles in SAMBA

Simply commenting out the following line does NOT switch it off. Leave the following line uncommented but specify an empty value:

[global]
..

logon path =

..

Wednesday, June 25, 2008

Samba Performance Tuning

If you are using Samba to be the file server for windows machines, you may need to tweak certain options within Samba to get it work more ideally for your setup.

This post assumes you have already set Samba up to be a file server or a PDC/file server and have already defined some shared folders.

Share level directives:
For shared folder where files may be accessed concurrently by multiple users, I find that the following permissions within the share definition in Samba are quite good:

security mask = 0775
directory security mask = 0775
force create mode = 0777
force directory mode = 0777

This ensures that new folders and files created are fully controllable by everyone.

For folders where files may be accessed by a few users and never concurrently, I find that the following options within the share definition in Samba are quite good. There are a host of windows programs that 'import' files to be used in data generation and analysis. This setting is especially crucial for that kind of setup:

level2 oplocks = True
oplocks = True

By specifying that the files can be locked by an application, import speeds are exponentially increased, however one may find that concurrent file access is slowed down.

Therein lies the difference:

If your files are meant to be shared concurrently by multiple users - the first section applies to you.
If your files are meant to be used by a few users and rarely, if ever, concurrently, then use the second section.

More information on oplocks and samba file locking can be found here:
http://www.samba.org/samba/docs/man/Samba3-HOWTO/locking.html

More information on files and directories in shares can be found here:
http://www.samba.org/samba/docs/man/Samba3-HOWTO/AccessControls.html


Global level directives:
I always add these options in the global section:

socket options = TCP_NODELAY IPTOS_LOWDELAY SO_RCVBUF=8192 SO_SNDBUF=8192

Fiddle with the last two options - SO_RCVBUF and SO_SNDBUF till you get performance you are happy with. Bear in mind, blindly doubling or tripling those numbers does not improve performance.

More information can be found here:
http://www.samba.org/samba/docs/man/Samba3-HOWTO/speed.html


Tuesday, June 24, 2008

Looking for Users on Mailserver in Linux

Linux mail servers have users' home directories in /home

Within the various user folders there may be .copy and .forward files that reference other user accounts by email address.

In addition users may be aliased in /etc/aliases

When a user gets deleted, they may still be referenced in a .copy, .procmailrc or .forward file somewhere or exist in the aliases db

Use the following script to check for a user's presence in one quick step:

#!/bin/bash

# This script helps search for usernames that are being copied, forwarded or
# aliased to.

USERNAME=$1;

# Go to the /home driectory
cd /home

# Search all .copy files and print the name out of the file that matches
echo ".copy references: "
grep -l $USERNAME `ls */.copy`
echo -e "\n"

# Same for .forward files
echo ".forward references: "
grep -l $USERNAME `ls */.forward`
echo -e "\n"

# Same for .procmailrc files
echo ".procmailrc references: "
grep -l $USERNAME `ls */.procmailrc`
echo -e "\n"

# Same for the /etc/aliases file
echo "Aliases File: "
cat /etc/aliases | grep $USERNAME
echo -e "\n"


I put this file in /root/bin as well. If you change this location, make sure you change the location in the script above.