Dec 12

Useful little shell productivity tricks:

I work remotely a lot. To avoid the lag associated with VPN’s and
to assure I have all the tools I love, I setup up an environment in
Cygwin that gets me all I need to do development. The one thing
that’s irritating is when it comes time to test in the customers
environment (or just a far machine). This is where this little while
loop comes in. I open a new xterm and

while :
do
rsync -zav /home/tony/work/SomeCustomerProject/ Far.Box.com:/home/tony/work/SomeCustomerProject/
read foo # wait here until any key is hit
fortune # gives me unique phrase/thought to remind me if I’ve pushed or not
done

After running the loop I resize the window down to one or two lines. Whenever I want to rsync, I focus on it and hit return.

Other ways to simulate a Linux/UNIX environment:

Netcat is native to Cygwin however you have to choose it in the ’setup’ app.
# simulate a network server – cats whatever is written, great for text protocols/SOAP, etc. Binary protocols will work, but you’ll have to go out of your way to translate them.
while :; do nc -n -t -vv -l -p 4913 127.0.0.1 ; echo “—–” ; done

Cygwin also implements named pipes:
mknode /usr/local/groundwork/nagios/var/spool/nagios.cmd p
# keep the pipe read so it doesn’t block
echo “while :; do cat /usr/local/groundwork/nagios/var/spool/nagios.cmd; done”

Mysql compiles under Cygwin. I use mysql-5.0.33.tar.gz because I have it laying around. It installs all the libs you need to compile DBD::mysql. It has pretty bad performance, but is great for development and light loads.

# add a user to cygwin’s /etc/passwd:
mysql:unused_by_nt/2000/xp:1003:513:mysql user:/usr/local/var:/bin/bash

### config line
./configure –enable-assembler –with-mysqld-ldflags=-all-static
make install # installs to /usr/local/*

After that it’s just a regular MySQL setup.

-Tony

written by admin

Sep 06
Some history and a cool command. Was originally used to print the X cut_buffer0 to lpr. Most of what it does is better done with a pipe,  but every once in while it’s the exact thing you need. 
Works under Cygwin X11.
#!/bin/sh
# return selected text. Mark Martin. cetia. france.
# xprop returned format is (eg) CUT_BUFFER0 = “echo \”cetia\\\”\n”
# get the \” and \\ and \n undone. sadly sed wont take long lines.
# sed wont read input not ending in newline, so need to chop off final newline
# use bell as newline marker.
# path added for xprop Frank Summers 1-31-91

# bell=^G
# bell=`echo “\07″`

# xprop -root -notype CUT_BUFFER0 |
# sed ‘1s/[^=]*= “//
# s/\\n/’”$bell”‘/g
# s/\\”/”/g
# s/\\\\/\\/g
# $s/”$//’ |
# tr -d ‘\012′ |
# tr $bell ‘\012′|
# lp

# Wed Mar 22 21:42:45 2000
# very old magic.
# Above is the original
# I got this from from an engineer at the Motorola Computer Group.
# i have done a minor rework so it is a bit cleaner in perl.

# Please note this is one long pipeline with comments in between
# Tony Hansmann (t o n y replacewith-at-sign open source consulting com)


xprop -root -notype CUT_BUFFER0|
perl -pe ’s!^CUT_\w+\s=\s\”!!x; # remove CUT_BUFFER0 = ” part
s!\\n!\n!gx; # make newlines appear as such
s!\\”!\”!gx; # make double-quotes appear as such
s!\\\\!\\!gx; # make back-slashs appear as such
s!\\t!\t!gx; # make tabs appear as such
s!\”$!!x;’

written by admin