Friday, August 3, 2012

Incremental/interruptable Unix/OSX file copy

I wanted to copy a large file to a Unix (OSX) system, and I knew it wouldn't complete before I took my laptop home.  Indeed, it would take a couple of days, so a couple of detaches would be needed.  I couldn't find anything that seemed to do the job I wanted, so I wrote the following script.  It takes two arguments: the from file and the to file.  It examines how large the to file is, and starts the copy from there, using 1 megabyte blocks. It won't work if the file changes during the overall copy operation of course.
#! /bin/bash

output_size=`du -m "$2" | cut -f 1`

if [[ $output_size = "" ]]
then
    output_size=0
fi

dd bs=1m seek=$output_size skip=$output_size if="$1" of="$2"

Thursday, June 28, 2012

OSX keyboard macros

OSX doesn't exactly come with keyboard macros, but it's not difficult to create them.  First, write an AppleScript that simply writes keystrokes to "System Events":
Save it to your "Library/Scripts" folder.

Then, add the key mapping you want to "System Preferences, Keyboard, Keyboard Shortcuts, Application Shortcuts".  Click the '+' to add one, use the name of the script you created, and choose a shortcut.  If you want to change the shortcut later, double click right over the characters for the shortcut.

I used this to create a shortcut when editing an html pre element, so it looks similar to http://formatmysourcecode.blogspot.com/

Wednesday, June 27, 2012

OSX, mail.app, and dovecot

OSX's mail.app can't seem to read files in /var/mail sent by, you guessed it: OSX itself. So, one can install dovecot from MacPorts and do a little configuration. First, set up a self-signed cert.
sudo mkdir -p /opt/local/etc/ssl/certs
sudo mkdir -p /opt/local/etc/ssl/private
sudo openssl req -new -x509 -nodes -config dovecot-openssl.cnf -out /opt/local/etc/ssl/certs/dovecot.pem -keyout /opt/local/etc/ssl/private/dovecot.pem -days 3650
Then, copy the example configuration
sudo cp /opt/local/etc/dovecot/dovecot-example.conf /opt/local/etc/dovecot/dovecot.conf
and make minor mods to dovecot.conf
sudo cp /opt/local/etc/dovecot/dovecot-example.conf /opt/local/etc/dovecot/dovecot.conf
sudo rcsdiff /opt/local/etc/dovecot/dovecot.conf
Password:
===================================================================
RCS file: /opt/local/etc/dovecot/dovecot.conf,v
retrieving revision 1.1
diff -r1.1 /opt/local/etc/dovecot/dovecot.conf
224c224
< #mail_location = 
---
> mail_location = /var/mail/%u
907c907
<     #args = dovecot
---
>     args = login
993c993
<     #args = 
---
>     args = 
And fire dovecot up
sudo port load dovecot

Monday, June 25, 2012

pulledpork lameness

All over the snort.org site it says "In order to manage rules we officially recommend and depend on the user using PulledPork." Well they must assume everyone is registered instead of subscribed as pulledpork doesn't work for subscribers. Lame. Here are the patches to make it work.
# rcsdiff ./pulledpork.pl 
===================================================================
RCS file: ./RCS/pulledpork.pl,v
retrieving revision 1.1
diff -r1.1 ./pulledpork.pl
368c368
<           getstore( "https://www.snort.org/reg-rules/$rule_file/$oinkcode",
---
>           getstore( "https://www.snort.org/sub-rules/$rule_file/$oinkcode",
435c435
<           getstore( "https://www.snort.org/reg-rules/$rule_file.md5/$oinkcode",
---
>           getstore( "https://www.snort.org/sub-rules/$rule_file.md5/$oinkcode",

Wednesday, June 20, 2012

Eucalyptus 3 notes

Changes made to /etc/eucalyptus/eucalyptus.conf
# rcsdiff -r1.1 eucalyptus.conf
===================================================================
RCS file: RCS/eucalyptus.conf,v
retrieving revision 1.1
diff -r1.1 eucalyptus.conf
55c55
< NODES=""
---
> NODES="172.19.0.2"
157c157
< VNET_MODE="SYSTEM"
---
> VNET_MODE="MANAGED-NOVLAN"
163c163
< VNET_PRIVINTERFACE="eth0"
---
> VNET_PRIVINTERFACE="eth1"
180c180
< VNET_BRIDGE="xenbr0"
---
> VNET_BRIDGE="virbr0"
191c191
< #VNET_PUBLICIPS="your-free-public-ip-1 your-free-public-ip-2 ..."
---
> VNET_PUBLICIPS="my public ips"
196,197c196,197
< #VNET_SUBNET="192.168.0.0"
< #VNET_NETMASK="255.255.0.0"
---
> VNET_SUBNET="172.19.0.0"
> VNET_NETMASK="255.255.0.0"
202c202
< #VNET_ADDRSPERNET="32"
---
> VNET_ADDRSPERNET="256"
206c206
< #VNET_DNS="your-dns-server-ip"
---
> VNET_DNS="my dns server"
211,212c211,212
< #VNET_BROADCAST="192.168.1.255"
< #VNET_ROUTER="192.168.1.1"
---
> VNET_BROADCAST="172.19.255.255"
> VNET_ROUTER="172.19.0.1"

I preferred to use a real class B private IP address as 192.168.0.0 with a subnet mask of 255.255.0.0 isn't a proper private network address.  I set up a simple system: a front end with the CC, SC, etc., and one NC via a crossover cable.

Note: as of this writing, one cannot create bundles on OS X boxen and have them work correctly.  You'll get a 'bad superblock' error...

Also note that that on page 28, there is essentially a typo.  For a MANAGED-NOVLAN setup, there is no need to create a bridge of any sort; xen will do that automatically.  And the "TYPE=Bridge" does not work under CentOS.

To find the latest release of euca2ools, look at http://downloads.eucalyptus.com/software/euca2ools/
For Eucalyptus itself: http://downloads.eucalyptus.com/software/eucalyptus/

Thursday, May 31, 2012

Scrollbars in Ubuntu 11++

Here's how one really gets back to the original scrollbars:
sudo bash -c "echo export LIBOVERLAY_SCROLLBAR=0 > /etc/X11/Xsession.d/80overlayscrollbars"
Logout, log back in.

Sunday, April 22, 2012

Linux and OS X OCR

Mostly for my notes:
pdftoppm -f 2 -gray AmericanLegion.pdf AL

for i in *.pgm
do
    pnmtotiff $i > ${i%%.pgm}.tif
    rm $i
done


for i in *.tif
do
    tesseract $i ${i%%.tif}
done
Tesseract needs images of decent resolution; e.g.: in PowerPoint it's better to "Save as Pictures" at higher than the default resolution: