Tuesday, June 2, 2009

The Command to check the disks and strip out unwanted variables

# The Command to check the disks and strip out unwanted variables
DISKSIZES=`df -k |grep / |awk '{print $5}' |sed -e 's/\%//'`


# Take the input from the df command above
for percent in $DISKSIZES
do

# If the percent is greater than the maximum percent that the disk slices are allowed to grow to
if [ $percent -gt $MAXSIZE ]
then

# Mail a df -k to the specified person(s)
echo $percent
df -k | mailx -s "Disk Space Problem on 'nodename' " $ADMIN_MAIL
fi

done

Test Perl connect Oracle

#!/usr/bin/perl

$oracle_server="";
$oracle_listener="";
$oracle_sid="";
$oracle_port="1521";
$oracle_user="";
$oracle_password="";
$oracle_table_de_test="dual";

use DBI;
use DBD::Oracle;

my $dbh = DBI->connect("dbi:Oracle:host=$oracle_server;port=$oracle_port;sid=$oracle_sid",$oracle_user, $oracle_password)
or die "khong the ket noi den database : " . DBI->errstr;

my $sth = $dbh->prepare("SELECT * FROM $oracle_table_de_test")
or die "prepare khong the thuc thi " . $dbh->errstr;

$sth->execute()
or die "khong the thuc thi cau sql: " . $sth->errstr;

while ( my @data = $sth->fetchrow_array() )
{
my $firstname = $data[1];
print "\t: $firstname \n";
}

if ($sth->rows == 0)
{
print "Table vide\n";
}

$sth->finish;

$dbh->disconnect;

Convert MySQL charset from Latin1 to UTF-8 easily

Latest versions of MySQL finally supports multiple charsets… This is great when you have to store date from different sources and manage multilingual application (especially the ones with glyphs and strange characters).

When migrating an application you may want to convert from Latin1 (ISO 88xx) charset to the most comprehensive Unicode UTF-8.

  • First of all made a dump of your database table.
  • Use iconv as follows:
    iconv -c -f latin1 -t utf-8 filename.sql > filename-utf8.sql
  • Backup the old table and truncate it.
  • Ensure every field has collation in utf8
  • Replace “latin1″ with “utf8″ in filename-utf8.sql
  • Reimport data and have fun ;-)