Ramblings from MostlyChris

Tech stuff and a bit more

Along with my megacli post, I need to remember how to check drives/RAID on an HP server so here it is.

hpacucli controller slot=1 ld all show

You'll need to replace the slot with the appropriate one for your configuration.

That should do it.

Suppose you would like to send a copy of an incoming email to another account while the email still goes to the original account. You can do this by modifying the .qmail file of the original recipient and adding an entry that looks like the following:

&user@domain.com

On a Plesk server, a full .qmail file with the above changes looks like this:

| true
&user@domain.com
| /usr/bin/deliverquota ./Maildir

Keep in mind that if you do this on a Plesk server, these changes will be overwritten with mchk or upgrades so you will have to take measures to deal with this. I set the files immutable so they can't be changed by Plesk. This causes its own problems so you will have to decide if it is worth it.

I ran into an issue in which I needed to test whether sqlite and the pdo plugin had support for UTF-8. From the documentation, sqlite3 should be able to handle this and other charsets. Further, the pdo should be charset agnostic. The following script should return UTF-8 because of the 'pound' symbol if indeed both items above are true.

<?php
try {
       $dbh = new PDO("sqlite::memory:", "charset=UTF-8");
} catch(PDOException $e) {
    echo $e->getMessage();
}

$sql = "create table t1 (id int, field1 varchar(255))";

try {
    $dbh->exec($sql);
} catch(PDOException $e) {
    echo $dbh->getMessage();
}

$sql = 'insert into t1 (id, field1) values (1, "A bit of text £")';
try {
    $dbh->exec($sql);
} catch(PDOException $e) {
    echo $dbh->getMessage();
}

$sql = 'select field1 from t1 where id=1';
try {
    foreach ($dbh->query($sql) as $row) {
        print "field1: " . $row['field1'] . "\n";
        print "Encoding: " . mb_detect_encoding($row['field1']) . "\n";
    }
} catch(PDOException $e) {
    echo $dbh->getMessage();
}

?>

Output of the above script should look similar to the following:

[rack@186451-db1 ~]$ php test.php
field1: A bit of text £
Encoding: UTF-8

Notice the UTF-8 output due to the pound sign being used in the text string.

I recently had to create a number of home directories from the user accounts in the /etc/passwd file because Webmin didn't create them when the user was created. Don't ask me why. Webmin is a mystery and only does things it feels like doing at the time it does them. But I digress..

The first thing I did was to create file with all users that have directories.

cat /etc/passwd | sed 's/:/ /g' | awk '($5 ~ /\//) { print $1 " " $5}' > file.txt

Edit the file you created and remove things like the postfix directory and other non-user account directories.

Next, run the command to create all of the home directories and then change their ownership to the user.

while read line; do mydir=`echo $line |awk '{print $2}'`; myuid=`echo $line| awk '{print $1}'`;  mkdir $mydir 2>/dev/null; chown $myuid:$myuid $mydir; done < file.txt

Follow these simple steps to setup an NFS client/server.

First, some housekeeping for this example.
Server machine (server) = 192.168.1.1
Client machine (client) = 192.168.1.2
Exported directory /nfs/export

### The server steps ###
1. Create an entry in /etc/exports with the exported directory and client IP.

/nfs/export 192.168.1.2(rw)

The (rw) sets the directory to be read and writeable. There are other options that can be specified here. Check out the NFS docs for more.

2. Edit /etc/hosts.deny and /etc/host.allow
In /etc/hosts.deny

portmap: ALL

In /etc/hosts.allow

portmap: 192.168.1.2

3. Start up portmap, nfs, nfslock, netfs on the server. These can most likely be found in /etc/init.d in the form of init scripts. Make sure they are set to start at boot with chkconfig (Redhat servers).

4. Run rpcinfo and make sure at least nfs, portmap and mountd are listed.

rpcinfo -p localhost



### The client steps ###

5. Make a directory that you you are going to use to mount the NFS share. Call it whatever you want.

mkdir /mount/nfsdir

6. Start portmap, nfs, nfslock, netfs on the client as you did on the server.

7. Mount the share.

mount 192.168.1.1:/nfs/export /mnt/nfsdir

8. Add an entry to /etc/fstab in order to have the share mount after a reboot.

192.168.1.1:/nfs/export  /mnt/nfsdir   nfs  rw  0 0

9. Test that you can create/delete/edit files and needed by your application.