Thursday, October 21, 2010

Dizzy Gillespie on Music

"...and all about how music can transport people spiritually."

Dizzy Gillespie in Carr, I., Fairweather, D, Brian P, The rough guide to Jazz. page. 291.

Tuesday, October 12, 2010

Using back references in SED

Today I have several CSV files, everyone with a header at the first line and a date at the first fields with the format mm/dd/yyyy. It was necessary to change that field into the format yyyy-mm-dd.

Here there is a Perl solution and also a SED one:

use strict;
use warnings;
while (<>) {
        if (/^[^0-9]/) {
                print "$_\n";
        my @Fields = split /,/, $_, 2;
        my ($Month, $Day, $Year) = split /\//, $Fields[0];
        print "$Year-$Month-$Day, $Fields[1]\n";

sed -i.bak 's/^\([0-9]\+\)\/\([0-9]\+\)\/\([0-9]\+\)/\3-\1-\2/' *.csv

Yesterday on my way home I realized that the Perl script was horrible, a one-liner should be OK, like the one below:

perl -i.bak -pe 's!(\d+)/(\d+)/(\d+)!\3-\1-\2!' *.csv

Monday, October 4, 2010

Deleting Glassfish old logs


DAYS_TO_KEEP=$((7 * 86400))     # In seconds
TODAY=$(date +%s)

for FileName in $(ls ${LOG_DIR}/server.log_*)
        FileDate=$(stat --printf=%Y ${FileName})

        DateDiff=$((TODAY - FileDate))

        if [ $DateDiff -gt ${DAYS_TO_KEEP} ]
                echo Deleting ${FileName} ${FileDate} ${TODAY} ${DateDiff}
                rm ${FileName}



Glassfish start/stop script for Ubuntu



case "$1" in
                #${GLASSFISHHOME}/bin/asadmin start-database
                ${GF_DIR}/bin/asadmin start-domain --user admin --passwordfile ${GF_DOMAIN_DIR}/config/password domain1
                ${GF_DIR}/bin/asadmin stop-domain domain1
                #${GLASSFISHHOME}/bin/asadmin stop-database
                ${GF_DIR}/bin/asadmin stop-domain domain1
                #${GLASSFISHHOME}/bin/asadmin stop-database
                #${GLASSFISHHOME}/bin/asadmin start-database
                ${GF_DIR}/bin/asadmin start-domain --user admin --passwordfile ${GF_DOMAIN_DIR}/config/passwordfile domain1
        echo $"usage: $0 {start|stop|restart}"
        exit 1