Tuesday, November 30, 2010

Configuring Sendmail RedHat /CentOS/Fedora

Configuring it is very simple. First you'll need the sendmail-cf package. Install it using yum:
[root@mail-server ~]# yum install sendmail-cf
Edit the file /etc/mail/sendmail.mc and add the following lines. Make sure you set your mail server domain name where it's bolded:
MASQUERADE_AS(yourdomain.com)dnl
MASQUERADE_DOMAIN(yourdomain.com)dnl
In the same file /etc/mail/sendmail.mc remove the "dnl" from the beginning of the lines so it will look like this:
LOCAL_DOMAIN(`localhost.localdomain')dnl
FEATURE(masquerade_envelope)dnl
FEATURE(masquerade_entire_domain)dnl
Save the file and compile it using m4:
[root@mail-server ~]# m4 /etc/mail/sendmail.mc > /etc/sendmail.cf
Send Sendmail a -HUP signal using kill or simply restart the daemon for the configuration changes to take effect:
[root@mail-server ~]# service sendmail restart

Testing your configuration using sendmail

And that's it! you're done. Just send yourself a test email to make sure it is really working:
[root@mail-server ~]# /usr/sbin/sendmail -t < mail.txt
Where the contents of the mail.txt file are:
Date: Wed Dec 1 08:41:54 2010
To: you@somewhere.com
Subject: The subject of the message
From: whatever@somewhere.com
Body of message goes here

Testing your configuration using mutt

You can also use mutt to test, which is a bit simpler (and you can also add the -a parameter for file attachment):
[root@mail-server ~]# mutt -s "Test Email" you@somewhere.com < /dev/null

Tuesday, November 23, 2010

Creating an ISO from a DVD MAC

From within Terminal (Applications->Utilities->Terminal)


You can determine the device that is you CD/DVD drive using the following command:

drutil status




Vendor   Product           Rev 
 MATSHITA DVD-R   UJ-875    DB09


           Type: DVD-R                Name: /dev/disk1
       Sessions: 1                  Tracks: 1 
   Overwritable:   00:00:00         blocks:        0 /   0.00MB /   0.00MiB
     Space Free:   00:00:00         blocks:        0 /   0.00MB /   0.00MiB
     Space Used:  425:20:48         blocks:  1914048 /   3.92GB /   3.65GiB
    Writability: 
      Book Type: DVD-R (v5)
       Media ID: SONY16D1
Now you will need to umount the disk with the following command:

diskutil unmountDisk disk1

Now you can write the ISO file with the dd utility:

dd if=/dev/disk1 of=dvd.iso

When finished you will want to remount the disk:

diskutil mountDisk disk1

Tuesday, November 16, 2010

Find WWN’s on RedHat /Cent OS

To find port and node WWN’s while the system is running:
  • 2.4.x Kernels
    > cat /proc/scsi/[hba_type]/(n)
    where hba_type is the driver (e.g. lpfc for Emulex) and (n) is the HBA number.
  • 2.6.x Kernels:
    > cat /sys/class/scsi_host/host(n)/[port_name|node_name]
    Hosts with multiple HBAs are enumerated via host(n) (e.g host0).
You can use lsmod to determine which driver is in use.

:)

Automated Bankup for Postgrsql

#! /bin/bash
# backup-postgresql.sh
# this script is public domain.  feel free to use or modify as you like.

DUMPALL=”/usr/bin/pg_dumpall”
PGDUMP=”/usr/bin/pg_dump”
PSQL=”/usr/bin/psql”

# directory to save backups in, must be rwx by postgres user
BASE_DIR=”/var/backups/postgres”
YMD=$(date “+%Y-%m-%d”)
DIR=”$BASE_DIR/$YMD”
mkdir -p $DIR
cd $DIR

# get list of databases in system , exclude the tempate dbs
DBS=$($PSQL -l -t | egrep -v ‘template[01]‘ | awk ‘{print $1}’)

# first dump entire postgres database, including pg_shadow etc.
$DUMPALL -D | gzip -9 > “$DIR/db.out.gz”

# next dump globals (roles and tablespaces) only
$DUMPALL -g | gzip -9 > “$DIR/globals.gz”

# now loop through each individual database and backup the schema and data separately
for database in $DBS; do
SCHEMA=$DIR/$database.schema.gz
DATA=$DIR/$database.data.gz

# export data from postgres databases to plain text
$PGDUMP -C -c -s $database | gzip -9 > $SCHEMA

# dump data
$PGDUMP -a $database | gzip -9 > $DATA
done

# delete backup files older than 30 days
OLD=$(find $BASE_DIR -type d -mtime +30)
if [ -n "$OLD" ] ; then
echo deleting old backup files: $OLD
echo $OLD | xargs rm -rfv
fi