Friday, November 29, 2013

Using corkscrew only if a reference host is unavailable

Here's a very simple solution if you sometimes have to use corkscrew and sometimes not when you could access the host directly.

I'm using socat to replace the corkscrew call if needed. Please comment if you know a better way.

Here's the script (called it selective-corkscrew):
#! /bin/bash

refhost="$1"
timeout=1

ping -w$timeout -c1 "$refhost" >/dev/null 2>&1 &&\
    exec socat - "TCP4:$4:$5" ||\
    exec corkscrew "$2" "$3" "$4" "$5"
And add this to your ~/.ssh/config. Replace what you have to:
Host *.domain
ProxyCommand selective-corkscrew referencehost.domain proxy.domain 3128 %h %p

Corkscrew is now only used if referencehost.domain doesn't answer the ping within 1 second.

If you don't know what's this all about, read this: using-corkscrew-to-tunnel-ssh-over-http!

Corkscrew Homepage

Monday, November 25, 2013

Useful Tools and One-liners

Find packages by size

dpigs

dpigs is available in the package debian-goodies. From the Manpage:
dpigs - Show which installed packages occupy the most space 

If you can't install debian-goodies for some reason, you can achieve the same result by this:


dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -nr | head
Or, to read from /var/lib/dpkg/status directly without the need of any tools:
sed -ne '/^Package: \(.*\)/{s//\1/;h;};/^Installed-Size: \(.*\)/{s//\1/;G;s/\n/ /;p;}' /var/lib/dpkg/status | sort -nr | head 
Thanks to this site:

Thursday, November 7, 2013

Amebix - Monolith

Always makes me feel good listening to this ... best album ever!


Friday, November 1, 2013

Windows: Shutdown from command prompt

How to reboot or shut down Windows from within a script, or even a remote session:
:: show shutdown dialog:
 shutdown -i

:: halt:
 shutdown -s

:: reboot:
 shutdown -r

:: reboot, open all registered applications afterwards:
 shutdown -h

:: log off user:
 shutdown -l

:: shutdown in 60 seconds:
 shutdown -t 60

:: abort shutdown (if previously invoked with -t):
 shutdown -a

:: close all applications without warning:
 shutdown -f

:: enter boot options menu after reboot:
 shutdown -o

:: turn off computer, no warnings:
 shutdown -p

:: hibernate:
 shutdown -h

:: shutdown a specific computer:
 shutdown /m \\HOSTNAME