Wednesday, February 15, 2012

bash history collector, without external scripts



# history_logger() side effects:
#   sets global variable '_last_history_number_logged'
#     $HISTCMD special variable should actually provide this,
#     But it appears unavailable in functions or at PROMPT_COMMAND eval time.
#
function history_logger() {
  local last_exit_code=$?   # must be the first command we run in this function
  local last_history_line=$(history 1)
  local _match_me="^ ?([0-9]+)"

  # Only log if we are not root:
  if [ "$(id -u)" -ne 0 ]; then
    # only log if history number changes:
    if [[ ${last_history_line} =~ ${_match_me} ]] &&
         [[ ${BASH_REMATCH[1]} != $_last_history_number_logged ]] ; then
      _last_history_number_logged=${BASH_REMATCH[1]} ;
      echo "$(date)] ${HOSTNAME%%.*}[$$:S${WINDOW}:${last_exit_code}] ${PWD/~/\~} ${last_history_line}" >> ~/.shell.log;
    fi ;
  fi
}

# the plumbing that makes it work:
export PROMPT_COMMAND='history_logger'


A few explanatory comments, as inline comments aren't available:
• HISTCMD does not appear to be available at function call or PROMPT_COMMAND time,
   so we use the [[ history =~ regex && BASH_REMATCH ]]  to hack it
• the assignment to ${_match_me} is because regex matching doesn't work correctly otherwise.
• the shell out to $(date) seems unavoidable.
• gnu screen is setting $WINDOW
• ${PWD/~/\~} is an exercise left to the reader.


I've seen other folks try to do this –– the best I found folks doing involved calling other bash scripts from the PROMPT_COMMAND.

I hit the same problem (inside a PROMPT_COMMAND, $HISTNUM is always == 1).
My solution uses a regex to capture the last history number, and doesn't require calling a separate script or set of scripts.

Comments welcome.

Wednesday, January 18, 2012

X11/xterm bliss in OSX


I was frustrated that selection buffer in Mac's OSX X11/XQuartz(2.7.0) xterm
and the aqua clipboard doesn't sync without manual use of the Edit/Copy menu.


I have menu shortcuts turned off in XQuartz so that Command becomes my xterm Meta key.



I found:
http://gigo.com/archives/blog/apples-x11app-and-xterm-copypa.html
which led me to setup my preferences and .Xresources file thusly:


My X11/XQuartz preferences:
Input tab:
• Enable "Emulate 3 button mouse "
• Disable "Follow system keyboard"
• Disable "Enable key equivalents under X11"
• Enable "Option keys send Alt_L and Alt_R"
Pasteboard tab:
• All are enabled.


~/.Xresources file:
xterm*metaSendsEscape:   true

XTerm*VT100.Translations: #override \
Shift <KeyPress> Help: insert-selection(CLIPBOARD,PRIMARY,CUT_BUFFER0) \n\
<KeyPress> Help: select-set(CLIPBOARD,PRIMARY,CUT_BUFFER0) \n\
<BtnUp>: select-end(CLIPBOARD,PRIMARY,CUT_BUFFER0)\n

+ my personal preferences:
xterm*loginShell:               true
xterm*cursorColor:              pink

xterm.vt100.reverseVideo:       false
!xterm.vt100.foreground:         yellow
!xterm.vt100.background:         black
xterm.vt100.saveLines:          1023
xterm.vt100.scrollBar:          false
xterm.vt100.deleteIsDEL:        true
xterm.vt100.visualBell:         true
xterm.vt100.popOnBell:          true

Tuesday, January 10, 2012

remote IP camera

list of applications for "DidICloseIt":
http://didicloseit.com/?page_id=129

vnc type apps
• https://market.android.com/details?id=net.xdevelop.rm Remote web desktop
• https://market.android.com/details?id=net.xdevelop.rc Remote control
• https://market.android.com/details?id=org.onaips.vnc  VNC server


adb shell /data/data/org.onaips.vnc/files/androidvncserver

Color Calibration

Nirvana or not?

[ howto printer color calibration ]
http://www.rpimaging.com/calibrate-printer.html

http://www.kenrockwell.com/tech/color-management/is-for-wimps.htm

http://www.normankoren.com/printer_calibration.html

http://www.inkjetart.com/custom/

Aperture + color profiles:  http://support.apple.com/kb/ta38346

Xrite - Workflows - Using Profiles with Third-Party Applications

printing in photoshop cs5 to epson:
http://www.gballard.net/photoshop/epson/cs5/

test images:

no color adjustment workflow:

calibrating your printer with displaymate;

Sharpening?

http://www.reallyjapan.com/blog/tutorials/how-to-sharpen-photos-in-photoshop/

Using ImageMagick

Extracting EXIF fun:

file:///opt/local/share/doc/ImageMagick//www/identify.html

and functions in FX:

file:///opt/local/share/doc/ImageMagick//www/fx.html

Wednesday, November 2, 2011

OpenWRT and Wake on Lan (WoL) how to make it work

The TP-Link Archer AC1750 C7 runs OpenWRT and is a great router IMHO.
You can also try the same hardware, rebranded by Amazon as the A7:
(There are many visitors to this page - but I'm not sure if any of this has helped others do what I did.
f the information below helps you, or you have questions, please use the comments to let me know.)

So, if you're trying to send a WoL wakeup packet to a single host on your LAN from your WAN segment, you'll need to use inbound port redirection.

Because I've not yet been able to make inbound NAT forward to my LAN's broadcast address,
you will need one "Redirection item" and a unique udp/port# pair per internal host, plus a static MAC address entry.

The missing static MAC entry is usually the second half of the puzzle that most folks don't figure out, and never get WoL working. This is something I think is broken in the kernel ip_tables module; it should log an error if a NAT redirection To: rule is missing from the ARP table, and the packet is being dropped due to lack of a MAC entry.

If you're using LuCI, this is done using a "Redirection" item.

Web Console path: admin/network/firewall
Here you will find three sections, (at least in my version, 10.03RC5 backfire):
• Zones
• Redirections
• Rules

To get WoL to work, I added one new Redirection item:

Name: WakeOnLan broadcast
Protocol: UDP
Source: wan:0.0.0.0/0:*
Via: Device:0.0.0.0/0:9
Destination: lan:192.168.1.69:*
Action: DNAT

Where 192.168.1.69 is an example internal LAN IP for the host you want to direct the WoL packets to.

As mentioned earlier, this isn't sufficient to make things work yet.

When the LAN host you're trying to wake up is powered off, it can't respond to ARP requests.
When a NAT packet is received by your router, it tries to forward it to the LAN segment, and perform DNAT.
Your router must know the ARP address of your To: destination host in order to send the UDP packet to it. And, since it's powered off, it won't know what that is, unless you set a static ARP address for it...

Where I found how to set a static MAC address:
https://forum.openwrt.org/viewtopic.php?id=1787

This command statically sets the ARP address for an IP.  (Replace 00:de:ad:be:ef:00 with your hosts's ethernet MAC address.)

ip neigh add 192.168.1.69    lladdr 00:de:ad:be:ef:00  nud permanent   dev br-lan


I added the above 'ip neigh add' command line to my router's
/etc/rc.local
file.

If the 'ip' command is not installed, you should be able to install it with '
opkg update; opkg install ip
'.


Note that if you change physical ethernet devices on this host, you'll have to update this line.


If you're still having trouble and you can do WoL from the local LAN, but can't get forwarding to work, drop me a note in the comments and I'll try to help.


If someone finds a way to get a Redirection rule to work with Destination: lan:192.168.199.255:* (the LAN broadcast address), please drop a note in the comments!


Cheers,
Marc.


#RSFtalks with Edward Snowden

What an intelligent, thoughtful individual. I find it difficult to forgive 44 for failing to pardon this patriot and instead pursuing him ...

Other Popular Posts: