Thursday, February 24, 2011

Geez python logging can be a pain

Geez python logging can be a pain in the ass making it difficult for novice programmers to debug stuff e.g.

This code ...

            logging.info ('>>>>>>>>>>>>' )
            logmsg = '339 init_facebook user email is ' , user.email.encode('ascii', 'ignore')
            logging.info ( logmsg )
            logging.info ('<<<<<<<<<<<' )

... works. See ...


INFO     2011-02-25 07:37:39,411 main.py:340] ('339 init_facebook user email is ', 'red.cricket.blog@gmail.com')
INFO     2011-02-25 07:37:39,411 main.py:341] <<<<<<<<<<<
INFO     2011-02-25 07:37:39,436 main.py:294] BaseHanlder render called

But this code  ...

            logging.info ('>>>>>>>>>>>>' )
            logging.info ( '339 init_facebook user email is ' , user.email )
            logging.info ('<<<<<<<<<<<' )

... gets this error message ...

INFO     2011-02-25 07:42:00,040 main.py:337] >>>>>>>>>>>>
Traceback (most recent call last):
  File "/usr/lib/python2.6/logging/__init__.py", line 768, in emit
    msg = self.format(record)
  File "/usr/lib/python2.6/logging/__init__.py", line 648, in format
    return fmt.format(record)
  File "/usr/lib/python2.6/logging/__init__.py", line 436, in format
    record.message = record.getMessage()
  File "/usr/lib/python2.6/logging/__init__.py", line 306, in getMessage
    msg = msg % self.args
TypeError: not all arguments converted during string formatting
INFO     2011-02-25 07:42:00,041 main.py:342] <<<<<<<<<<<

What heck is the diff command I need to run for patch?

Here is an excellent article on this issue:

http://stephenjungels.com/jungels.net/articles/diff-patch-ten-minutes.html

Here is what I need to do ...


$ cvs diff -u -r1.27 -r1.26 my_file.conf > patch_back_to_r1.26
$ patch < patch_back_to_1.26
patching file my_file.conf

How do I see the revision 'notes' / 'comments' change history in CVS?

$ cvs log thefile

Monday, February 14, 2011

Interesting way to start Perl

#!/bin/sh
## Save STDERR; Redirect to /dev/null while we search for a version of Perl with Net::SMTP;
exec 3>&2 2>/dev/null
test -z "$perl" && test -x /usr/local/perl5.8.5/bin/perl && perl=/usr/local/perl5.8.5/bin/perl
test -z "$perl" && test -x /usr/local/perl5.6.1/bin/perl && perl=/usr/local/perl5.6.1/bin/perl
test -z "$perl" && test -x /usr/local/bin/perl           && perl=/usr/local/bin/perl
test -z "$perl" && test -x /usr/bin/perl                 && perl=/usr/bin/perl
test -z "$perl" && test -x /usr/cisco/bin/perl           && perl=/usr/cisco/bin/perl
test -z "$perl" && test -x /usr/local/bin/perl5.6        && perl=/usr/local/bin/perl5.6
export perl
## Restore STDERR from fd 3 and close fd 3.
exec 2>&3 3>&-
## Start the selected version of perl; "-x" says to ignore everything up to #!perl.
exec $perl -x $0 $*
#!perl

$ENV{PATH} = "/usr/sbin:/usr/bin:/usr/lib:/bin";

chomp($thisHost = qx{uname -n});
chomp($os       = qx{uname -s});
chomp($release  = qx{uname -r});

$interval  = 120;                       # Interval, in seconds.
if ($os eq "Linux") { ...

Tuesday, February 08, 2011

if statement with -a (and) operator

#!/bin/sh
DCDIR=/usr/data

lc=unknown
if [ -e /etc/config/local/lc.cfg ]
then
        lc=`cat /usr/XX/config/local/lc.cfg`
fi

if [ "$lc" != "prod" -a "$lc" != "stage" -a "$lc" != "dev" ]
then
        echo "ERROR $0 bad lc of $lc"
        exit 1
fi

echo "Good lc $lc"

Cool web page

http://www.overthewire.org/wargames/vortex/