2010
02.01

Debugging python…

insert

import pdb; pdb.set_trace() 

in to area of code area you would like to debug then run script.

These commands allow you to step through the code from the point of where pdb.set_trace() is placed in your script.

p – print the content of an object
n – next line
c – continue through rest of script, to next break point, or next pdb.set_trace()
s – step in to function/routine and make edits or view
var = ‘new value’

start with this script.

#!/bin/env python
import pdb

var_0 = 'day'
var_1 = 'night'

print '   var_0: %s\n   var_1: %s' % (var_0, var_1)
#pdb.set_trace()

print 'from %s in to %s and back again.' % (var_0, var_1)

run it with the pdb line commented and you get this.

$ ./day.py
   var_0: day
      var_1: night
      from day in to night and back again.

Now uncomment the pdb line and run it again.

$ ./day.py
 var_0: day
 var_1: night
> /home/msnow/bin/day.py(10)()
-> print 'from %s in to %s and back again.' % (var_0, var_1)
(Pdb) n
 from day in to night and back again.
--Return--
> /home/msnow/bin/day.py(10)()->None
-> print 'from %s in to %s and back again.' % (var_0, var_1)
(Pdb) n
$

This shows you part of the program running, then dropping in to the debugger just before the area of code you want to look at.
Now we will change the values assigned to val_0 and val_1 withough editing the file.

$ ./day.py
 var_0: day
 var_1: night
> /home/msnow/bin/day.py(10)()
-> print 'from %s in to %s and back again.' % (var_0, var_1)
(Pdb) var_0
'day'
(Pdb) var_1
'night'
(Pdb) var_0 = 'morning'
(Pdb) var_1 = 'evening'
(Pdb) n
from morning in to evening and back again.
--Return--
> /home/msnow/bin/day.py(10)()->None
-> print 'from %s in to %s and back again.' % (var_0, var_1)
(Pdb) n
$
2010
02.01

i’ve been learning bits of python here and there for work and for play and I came across a simple solution to a simple problem I had to solve in python.
There are some things in python that once you realize how things work you think “that is so simple!”. I had one of those moments.

This particular solution came up when the need to compare user disk quotas arose on different filers.

list_a = { 'a' : 123, 'b' : 456 }
list_b = { 'a' : 321, 'b' : 654 }
list_c = {}
for key, val in list_a.items():
    for que, wal in list_b.items():
        if key == que:
            list_c[key] = [ val, wal ]
list_c
{'a': [123, 321], 'b': [456, 654]}
2010
01.10

One of the features I’ve seen on network cards for as long as I can remember is Wake On LAN. I’ve known what the feature is and how it works in principal but never taken the time to set it up.
Yesterday I took the time to google around and came across This How-To on one of my favorite OpenBSD info sites, Calomel.org.

I setup a cron job on my OpenBSD router to wake up my Ubuntu box in the living room at 5:30pm, and another cron job on the Ubuntu box to poweroff at midnight.

Now i’ll waste just a bit less power in my home. Now if only I could get my electric bill below 1000kWh per month…

2009
12.29

I had been running the 180 nvidia drivers from another PPA a while then vdpau stopped working, turns out the PPA moved here.

Add these two lines to your /etc/apt/sources.list, then apt-get remove mplayer && aopt-get install mplayer

deb http://ppa.launchpad.net/nvidia-vdpau/ppa/ubuntu karmic main
deb-src http://ppa.launchpad.net/nvidia-vdpau/ppa/ubuntu karmic main

And if you want to setup a Squeezebox server…

## SlimDevices Squeeze box
deb http://debian.slimdevices.com testing main

2009
12.28

MySQL password recovery

I always forgot the procedure for mysql pw recovery so i’m posting it to my blog.
This is a re-post from DebianAdmin.com.

By default, MySQL Server will be installed with root superuser without any password. You can connect to MySQL server as root without requiring password or by keying in blank password. However, if you have set the password for root and forget or unable to recall the password, then you will need to reset the root password for MySQL.

Login as root to the Unix-like (Unix, Linux or BSD) machine with the MySQL server.

Stop the MySQL server by using either of the following command


#/etc/init.d/mysql stop

Now you need to Start MySQL server without password

# mysqld_safe --skip-grant-tables &

Connect to mysql server using mysql client with the following command

# mysql -u root

Now you should be having mysql prompt

mysql>

Now you need to Setup new MySQL root user password

mysql> use mysql;
mysql> update user set password=PASSWORD(“newrootpassword”) where user=’root’;
mysql> flush privileges;
mysql> quit

Note: Replace newrootpassword with the new root password for MySQL server. Flush Privileges is needed to making the password change effect immediately.

Now you need to Stop MySQL Server using the following command

# /etc/init.d/mysql stop

Test Your New Mysql root password

First you need to start mysql server using the following command

# /etc/init.d/mysql start
# mysql -u root -p

Now it will prompt for root password and enter your new root password

2009
12.10

the ultimate screen setup

my buddy Josh whom I am now working with at Xilinx sent me this. it is the ultimate configuration for one of my favorite time saving apps, screen.


cat ~/.screenrc
vbell off
#
# Change this to the character you wish to use with ctrl instead of 'A'
#
# i.e. escape "``" means ctrl-` `
# escape ^zz
scrollback 10000
hardstatus alwayslastline
hardstatus string '%{= kG}%-Lw%{= KW}%50>%n%f* %t%{= kG}%+Lw%<'

2009
12.10

*NIX dump/restore command primer…

my old pal David sent this to me. he is a super old school lovin unix guy. He has an original Next cube.


dump 0uaf usr.dump /usr
mkdir /tmp/restore
cd /tmp/restore
restore if /path/to/usr.dump (interactive)
restore rf /path/to/usr.dump (restore everything)
cd, ls, add files
extract

2009
12.01

FreeCiv on Sun X4540 ILOM….

Just doing some friendly nmap scans on an internal network and found this.

Interesting ports on 192.168.200.253:
Not shown: 995 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
80/tcp   open  http
443/tcp  open  https
5120/tcp open  unknown
5555/tcp open  freeciv
MAC Address: 00:14:4F:8D:30:7C (Sun Microsystems)

Thought that was kinda funny to have on an X4540 ILOM. :)

2009
12.01

New job and server moved…

Tomorrow is my last day as a sysadmin for Greenplum. It’s been an awesome ride and I am thankful for the opportunity the company has given me. Next week I begin a new role at Xilinx working with a couple of great friends supporting a large and growing team of engineers. It will certainly be an interesting, and welcome change of pace to my life. :)

I also moved slakin.net|mattsn0w.com and other domains I host to an awesome inexpensive VPS in Texas, FiveBean.com. If you sign up, click HERE so I get a referral bonus on my account. :)

2009
11.08

I was reading this blog post by Matt Simmons (a stand alone sysadmin like myself) he linked to a great security blog mckeay.net where I read this post. I found it oh so amusing as I’ve seen the same sort of thing at work.

Hopefully nobody from work reads my blog! :)