extract and reload mysql database — GZIP on the fly.

To dump a mysql database use the mysqldump command and pipe it to gzip on the fly so the resulting backup file is compressed with this command:

mysqldump -u[uname] -p [dbname] | gzip – > backupfilename.dmp.gz

To restore this on another machine you need to create the databse using mysqladmin

mysqladmin -u[uname] -p create schemaname

Then load the data with

gunzip < [backupfile.sql.gz] | mysql -u [uname] -p[pass] [dbname]

Posted in Uncategorized | Leave a comment

HDPVR IR Blaster working with Ubuntu 10.10

Upgrading to Ubuntu 10.10 caused my HDPVR ir blaster to stop working, again…

I had to re-figure out how I got it working int he first place, so I figured I’d write it down this time.

Ubuntu 10.10 comes with hdpvr drivers compiled and included in /lib/modules/2.6.35-24-generic/kernel/drivers/media/video/hdpvr/hdpvr.ko
BUT these drivers DO NOT support using the IR blaster function.

So you have to compile them yourself.

The lirc_zilog driver which is needed is included with 10.10 ubuntu ( it is in the staging area: /lib/modules/2.6.35-24-generic/kernel/drivers/staging/lirc/lirc_zilog.ko)

But in previous versions I had to compile that separately, but this time it worked using the distributed version.

To get the hdpvr drivers recompiled, I used the source code I had working before. I think I got it from the links on this page: http://www.mythtv.org/wiki/HD-PVR
Which has the software linked here: http://www.themainlan.com/mythtv/hdpvr-blaster-drivers.tar.gz

Usually the drill when you get a new kernel is to go to the directory for the hdpvr and
make clean
make
and copy the hdpvr.ko file to the appropriate /lib/modules directory

But this time it wouldn’t compile.

I had to change some function calls that had been renamed in the new kernel:

Change:
usb_buffer_alloc() to usb_alloc_coherent()
and
usb_buffer_free() to usb_free_coherent()

And the the video_is_unregistered function call to be changed to ( ! video_is_registered )

All working again — and now I have mythtv 0.24 🙂

I have the apps in /usr2/apps/hdpvr ( got the

Posted in Uncategorized | Leave a comment

Moving SVN repositories

To move a subversion repository just dump the repository.
Here is a little script to dump all /var/svn repositories to their own portable dump.gz file:

#!/usr/bin/perl

## backup each repository in /var/svn to a file dirname.svn.dmp.gz
## and push to repository

$single = shift;

$DIR = “/var/svn”;
opendir(DH,”/var/svn”);

while ( $repo = readdir(DH) ) {
next if $repo =~ /\./g;
next unless $repo =~ /$single/;
$cmd = “svnadmin dump $DIR/$repo | gzip -c > /repository/tcg_backup/$repo.dmp.gz”;
print “\n$cmd”;

system($cmd);

}

Create new repository on new site

$DIR=”/var/svn”;
$TMP=”/tmp”;

chdir($DIR);

$single = shift;

foreach $repo (@repos) {

next unless $repo =~ /$single/;

print “\npulling $repo”;
$repo =~ /^(.*)\.dmp\.gz/;
$name = $1;

# remove old dump file
unlink(“$TMP/$repo”);

# remove any old repository directory
$cmd = “rm -rf /var/svn/$name”;
print “\n$cmd”;
system($cmd);

$cmd = “cd $TMP; wget –no-check-certificate https://10.5.20.103/repository_pull/tcg_backup/$repo”;
print “\n$cmd”;
system($cmd);

die “Could not get file from repository” unless -s “$TMP/$repo”;

$cmd = “cd /var/svn; svnadmin create $name”;
print “\n$cmd”;
system($cmd);

$cmd = “cd /var/svn; gunzip < $TMP/$repo | svnadmin load $name"; print "\n$cmd"; system($cmd); } $cmd = "chown -R apache:apache /var/svn"; print "\n$cmd"; system($cmd);

SWITCH your existing working copies to point to the new machine with this nifty little svn switch command:

svn switch –relocate https://10.5.20.103/svn/cobra/trunk https://svn_repo.colum
biagroup.com/svn/cobra/trunk

Posted in Uncategorized | Leave a comment

Growing an ext3 filesystem under ESXI

NOTE: This can only be done on filesystems that can be unmounted. (i.e. You can’t do it on /root unless you boot from a rescue CD )

First unmount the file system

umount /big1

Next, convert ext3 –> ext2 filesystem by turning off journaling

tune2fs -O ^has_journal /dev/sdb1
e2fsck -v -f /dev/sdb1

In VSPHERE Client Edit settings on the VM and Increase the size of the.vmdk

Right Click on the VM in the tree
Select Edit Settings….
Select the Hard Disk you want to grow.
Enter New Size
Click OK

To get the RUNNING OS to recognize the new drive size.

REMOVE the hard drive ( but tell it to keep the data!)

Do this by clicking the remove button when the hard disk is selected.

RE-ADD the disk by clicking ADD – select Hard Drive. Select use existing VMDK file.

Browse to the Data Storage for the VMDK you just removed and add it back.

If you run dmesg on the OS it should show the Drive being removed and then re-added.

Now when you do fdisk you’ll see the larger size.
In FDISK you resize the partition by deleting it and recreating it to use all the cylinders.

fdsik /dev/sdb
p
d
n
Hit enter twice
w

Run resize2fs /dev/sdb1 to get the filesystem to recognize the larger partition size

resize2fs /dev/sdb1

Convert back to ext3

tune2fs -j /dev/hdax
e2fsck -v -f /dev/hdax

Mount the filesystem

mount /big1

Posted in Uncategorized | Leave a comment

Moving Mysql database data directories to new partition

If you need to move a mysql database’s data files to another partition because space on /var/lib/mysql is getting low you can do this:

1) Shut down the database

service mysqld stop

2) move the database files using cpdir

cd /var/lib/mysql/databasename
find . -depth -mount -print | cpio -pdmv /NEWPARTITION/mysql/databasename

3) Rename the old directory
4) Create a symbolic link between old and new directory

5) Fix context (SE linux Permissions) on the new directory has good SELINUX permissions.

chcon -R -u system_u -r object_r -t mysqld_db_t /NEWPART/mysql

Posted in Uncategorized | Leave a comment

Samba Shares and SE Linux

Any samba shares need to have the context changed.

chcon -R -t samba_share_t /cc_share

If you want to have home directories not enforce SE linux permission denial for homes just issue this command:

setsebool -P samba_enable_home_dirs 1

Posted in Uncategorized | Leave a comment

Configuring Apache on CENTOS:
Just some random notes on what I had to do to get my Perferred tools installed on Apache under centos:

yum install php-Smarty php-pear php-pear-MDB2 php-mysql

To get pear configured I ran these commands:

pear upgrade MDB2
pear install ‘MDB2#mysql’
pear channel-discover pear.firephp.org
pear install firephp/FirePHPCore

After starting up mysqld I ran the script to set root password and lock down the mysql db:

service mysqld start

/usr/bin/mysql_secure_installation

=======

Other useful commands:

chcon -R -h -t httpd_sys_content_t www

service httpd restart

mkdir /usr2/apps/Smarty

cd /usr2/apps/Smarty

wget http://www.smarty.net/do_download.php?download_file=Smarty-2.6.26.tar.gz

tar xozvf Smarty-2.6.26.tar.gz

mkdir /usr/local/lib/php

mkdir /usr/local/lib/php/Smarty

cp -r Smarty-2.6.26/libs/* /usr/local/lib/php/Smarty

Set include path:

vi php.ini

AND MAKE FOLLOWING edit tot he include path line

include_path = “.:/usr/share/php:/usr/local/lib/php/Smarty:/usr/share/pear”

Restart Webserver

service httpd restart

Posted in Uncategorized | Leave a comment

Calculating the Fiscal Year in Excel

Jason came up with this nifty formula to calculate the fiscal year in excel based on a string in the YYYY-MM-DD format.
It could be adapted to support other formats by changing the MID substring values ( MID is the excel Substring function).

This example references a date in cell AB7 — you’ll have to change that to refer to your date field.

=IF(MID(AB7,6,2)=”10″,MID(AB7,1,4)+1,IF(MID(AB7,6,2)=”11″,MID(AB7,1,4)+1,IF(MID(AB7,6,2)=”12″,MID(AB7,1,4)+1,0+MID(AB7,1,4))))

Posted in Uncategorized | 1 Comment

Using CRL lists with PKI certificate of authorities

Notes from 3/8/2010  troubleshooting crl issues.

Users called and could not access the cobra web site.

They were using certificates issued by Verisign – specifically:

CN=VeriSign Client External Certification Authority – G2

I checked our page using the command:

openssl s_client -showcerts  -connect usecobra.com:443 -prexit

and we were not accepting verisign G2 cert on cobra

So I went to the DISA webpage: https://crl.chamb.disa.mil/

NOTE:  a quicker way to get the new cert is to cut and paste from the view screen after selecting a cert on the left and clicking view on the right side of the page.

This is an ascii representation of the cert known as PEM format.  ( as apposed to the .DER format  which is binary that you get when you use the download link.

For our purposes we want the PEM format ascii file to put in our ca-bundle.txt

I like to put the PEM cert in a file by itself to verify it.  I named this one verisign_ECA_G2.crt

Then I can run this to verify and get the issuer / subject to up in the comments.

openssl x509 -inform PEM -in verisign_ECA_G2.crt -issuer -subject –noout

issuer= /C=US/O=U.S. Government/OU=ECA/CN=ECA Root CA 2

subject= /C=US/O=U.S. Government/OU=ECA/OU=Certification Authorities/CN=VeriSign Client External Certification Authority – G2

I edited the ca-bundle.crt to add the comments at the top and the cert.

I add the code like this:

#############################################

#subject= /C=US/O=U.S. Government/OU=ECA/OU=Certification Authorities/CN=VeriSign Client External Certification Authority – G2

#issuer= /C=US/O=U.S. Government/OU=ECA/CN=ECA Root CA 2

—–BEGIN CERTIFICATE—–

MIIF7DCCBNSgAwIBAgIBCjANBgkqhkiG9w0BAQUFADBNMQswCQYDVQQGEwJVUzEY

MBYGA1UEChMPVS5TLiBHb3Zlcm5tZW50MQwwCgYDVQQLEwNFQ0ExFjAUBgNVBAMT

DUVDQSBSb290IENBIDIwHhcNMDgwNzAyMTQ0MTE4WhcNMTQwNzAxMTQ0MTE4WjCB

X158kXsnY2wvH2WdMMpHmj7GvikIw/tP/7w9/uwe6mE=

—–END CERTIFICATE—–

ON linux just restart the webserver to make it take affecte

service httpd restart

On oracle it is a little more complicated:

Log in as oracle

. formsset

cd /ora/wallets

## Save off the wallet.p12  for backup

cp wallet.p12 wallet.p12.100308

Edit ca-bundle.crt as described above.

Run ./import_cert which will “recomple” the wallet.p12 by running this command:

/ora/10ias/Apache/Apache/bin/ssl2ossl -cert /ora/wallets/usecobra.com.crt -key /ora/wallets/usecobra.com.key -cafile /ora/wallets/ca-bundle.crt -wallet /ora/wallets

You will need the password for the wallet as well as the key to complete this command.

Note – if it fails that means the cert you added is invalid – OR you do not have the cert for the all the parents up the chain of the issuer of that cert.

Then to restart the webserver on Oracle Solaris run the following commands

$ORACLE_HOME/opmn/bin/opmnctl status

$ORACLE_HOME/opmn/bin/opmnctl stopproc ias-component=HTTP_Server

$ORACLE_HOME/opmn/bin/opmnctl startproc ias-component=HTTP_Server

$ORACLE_HOME/opmn/bin/opmnctl status

Out of date CRL lists!!!

We found out today that the reason G2 certs from verisign were not being accepted was because the CRL file for Verisign we had in place was out of date.

All certs from an issuer whose CRL is expired are rejected until we get  a valid CRL list from that issuer – this is the concept that if my guest list is considered obsolete – no one from that source will get in.  Make sense.

openssl crl -inform DER -in /etc/httpd/crl/VERISIGNCLIENTEXTERNALCERTIFICATIONAUTHORITY_G2.crl -text | less

The command above will show the revoked certs by date and reason – as well as the “validitiy dates” for the list

Certificate Revocation List (CRL):

Version 2 (0x1)

Signature Algorithm: sha1WithRSAEncryption

Issuer: /C=US/O=U.S. Government/OU=ECA/OU=Certification Authorities/CN=VeriSign Client External Certification Authority – G2

Last Update: May 29 15:23:49 2009 GMT

Next Update: May 30 09:23:49 2009 GMT

In the above example has a Next Update date – after that time no one with a verisign G2 signed cert will be able to get in.

Posted in Uncategorized | Leave a comment

converting julian date to real date in mysql

We’ve got data that uses a funky date format — not a true julian date  but the Year followed by the DAY of the year.

i.e.

2010005 = January 5th, 2010

2010031 = January 31st 2010

2010365 = December 31st 2010

This little snippet of code will allow you to select it from the mysql database and convert it to a real date.

select date_sub(date_add(concat(substr(jdate,1,4),’-01-01′), interval substr(jdate,5,3) day ), interval 1 day)

so in this example below returns May 2 ( the 123rd day of 2004 is May 2 )

select date_sub(date_add(concat(substr(‘2004123′,1,4),’-01-01′), interval substr(‘2004123’,5,3) day ), interval 1 day)

Posted in Uncategorized | Leave a comment