Friday, January 13, 2012

Ssh tunnels are great


At work I'm connecting to multiple Munin statistics servers. On my lappytop I'm only running one server, so how do I get multiple sets of results?  Answer: create a tunnel to another server!


The Munin protocol is extremely easy, send "fetch X" to get statistics on X.  In my example df=Disk File usage.  Here's how to get local information, via Munin running locally on port 4949.



$ echo 'fetch df' | nc -q1 localhost 4949
# munin node at freebeer
_dev_sda1.value 5.29318865322941
_dev.value 0.0339391645617528
_dev_shm.value 0.378827479751794
_var_run.value 0.00922469512382616
_var_lock.value 0
.

Here's how to make a remote machine's Munin (on port 4949) show up on localhost (port 4950). This means we can scan multiple local ports to get information on many different machines.

ssh -fNL localport/localhost/remoteport remotehost

Option "-f" means drop into the background after asking for a password.  Next option "-N" is so the ssh connection doens't try to run anything remotely.  The next bit actually creates the tunnel.  It reads (L)ocal port 4950 maps to remotehost 4949.  The "localhost" in slashes is in respect to the connected session -- from our perspective it's remotehost.

Here it is in context.  Establish a tunnel, use it to get Munin Disk Filesystem information for the remote host.


$ ssh -fNL 4950/localhost/4949 myremotehost


$ echo 'fetch df' | nc -q1 localhost 4950
# munin node at myremotehost
_dev_xvda2.value 3.15090884943856
_dev.value 0.022631566185207
_dev_shm.value 0
_var_run.value 10.3138711271508
_var_lock.value 0
_lib_init_rw.value 0
.

http://www.engadget.com/2006/03/21/how-to-ssh-tunnels-for-secure-network-access/

Sunday, December 11, 2011

backing up an Android device

My beloved Cheese, a Samsung Galaxy S Android phone, has lots of photos on it.  I want copies on my main Ubuntu computer.  Also Cheese is complaining about running out of room, even though I'm down to 130 apps -- I want to examine the phone and delete hidden files taking up precious space.  To do all this I'm installing a file server on the phone, then editing and copying things at my leisure from the main computer vs using the fiddly little phone screen.

1. Install Software Data Cable on Android.  This is an FTP server for your phone, so you can easily see  files on the phone and copy to/from your computers.
Another choice is the excellent ASTRO File Manager, which has a SMB (Windows network file system) module.

2.Start Software Data Cable.  Press "Start Service"

3. In Ubuntu, open the URL given in step #2, like ftp://192.168.11.148:8888/  If all is well you'll see a listing of Android application folders, like "camera360".

4. To sync files, drag and drop using the above file manager, Nautilus.  Or use "wget" which understands FTP. The following says "make a copy on my PC of all JPG images stored on the SD card on the phone. Keep all directories the same."


wget --mirror -nv --accept jpg ftp://192.168.11.148:8888/ .

If things don't look right try the above command and leave off "-nv" to make things more verbose.

Note that the above only gives you access to the "external SD card" parts of the Android phone.  The other, "internal" flash are generally hidden.  To access this area anyway you can enable it in Data Cable's settings area -- but this is sketchy and not recommended.



Monday, October 24, 2011

Linux is awsome

At work we process many millions of emails a day, so we get a lot of bounces. The following code helps me make the system smarter. It translates to "for the most recent five users who's received a bounce message, find all of their bounces in the last 24 hours and show me the Subject lines, with user and date information."

find `ls -1t | head -5` -type f -mtime -1 -print0 | xargs -0 egrep Subject /dev/null | less

Wednesday, October 19, 2011

Webex with Ubuntu Oneiric Ocelot

Read elsewhere how to install all the needed dependencies. Here's a magic bit:

sudo add-apt-repository "deb http://archive.canonical.com/ natty partner"
sudo apt-get update
sudo apt-get install sun-java6-plugin

A final trick: I use Firefox for work stuff, and Chrome for personal tasks -- thus I don't have to deal with multiple profiles, nor does sketchiness in one browser affect the other.

Friday, September 30, 2011

I love Python (espeak speech synthesizer demo)

#!/usr/bin/env python

'''
espeak.py -- demo each of the English espeak voices
'''

import os, re, time
from itertools import ifilter, imap

# Pty Language Age/Gender VoiceName File Other Langs
# 5 en M default default

pat = re.compile('\s* \d+ \s+ (en\S*) \s+ \S \s+ (\S+)',re.VERBOSE)
for m in ifilter(None, imap(pat.match, os.popen('espeak --voices=en'))):
lang,voice = m.groups()
if '-' in lang:
continue
print voice
os.system('espeak -v {0} "{0}... beer is good food" 2>/dev/null >/dev/null'.format(
voice))
time.sleep(3)




https://github.com/shavenwarthog/setup/blob/master/misc/espeak.py