Thursday, August 06, 2009

Debian Lenny in qemu on Windows

http://homepage3.nifty.com/takeda-toshiya/qemu/

Create an image to install into:

qemu-img.exe create -f qcow qemu_disk.img 3G

Download install image:

http://www.debian.org/CD/netinst/


Copy and change qemu-win.bat

To boot the install image with:
qemu.exe -L . -m 128 -hda qemu_disk.img -soundhw all -localtime -M -cdrom debian-503-i386-netinst.iso

Then to run normally, remove the -cdrom part.

I have also used: -m 256 -cpu pentium3 -M pc -no-reboot -no-acpi -no-kqemu

To do this I copied qemu-win.bat to a new batch file, and edited that to suit my needs and use that to start qemu.

There maybe a few errors when it boots, but nothing serious - and I can run it on a machine where I don't have admin, where I can't install VirtualBox or similar.

If you add:

-redir tcp:22::22
You can ssh into localhost to get into the machine.
-redir tcp:2222::22 if 22 is already in use...

Other links:
http://lassauge.free.fr/qemu/
http://www.davereyn.co.uk/download.htm ?

Friday, July 17, 2009

rolling back a commit with git

Get the hash of the version you want...


$ git log


Check out the version into the current dir:


git checkout 45a5b1aa137c07b15f820f49762feb7ec068b3f8 .


http://stackoverflow.com/questions/373812/rollback-file-to-much-earlier-version

Tuesday, March 03, 2009

Dead ringer...

How to disable bells all over the place...

To turn off that annoying flash (that lags your session) in vim:

In .vimrc


set vb t_vb= " Turn off visual bell


General beeps...

In .inputrc


set bell-style none


In ~/.bash_profile (or /etc/profile or .bashrc or somewhere)


setterm -blength 0


In X Window:


$ xset b off


To turn it on again use:


$ xset b on


For less

In ~/.bash_profile:


export LESS="-q"

Monday, February 23, 2009

htmlify a script -x


sh -x try.sh 2>&1 | sed "s/^+ \(.*\)$/\n$ <b>\1<\/b>/g;"

heads or tails? don't be so negative...

The number of lines options with head and tail do not have to be negative...

After 15 years of using head and tail (and wondering why they encourage the use of the "extra" '-n' option now!) a question just occurred to me...

"What if I don't know how many lines I want to see with tail, I just know I want to skip the first X lines...?"

The logical opposite of:

tail -X FILENAME

would of course be:

tail +Y FILENAME

Which (thanks to Unix being so logical) naturally works!

You wouldn't really want to use it without a -n in front because +NUM would more likely be a valid file name than a switch, so you do get a warning:


$ tail +20 FILENAME
tail: Warning: "+number" syntax is deprecated, please use "-n +number"


and head just barfs:


$ head +20 FILENAME
head: cannot open `+20' for reading: No such file or directory


So use:


$ tail -n +$SKIP FILENAME


Given the file:


$ seq 1 5 > FILENAME
$ cat FILENAME
1
2
3
4
5


Let's unit test...


$ head +2 FILENAME
head: cannot open `+2' for reading: No such file or directory
==> FILENAME <==
1
2
3
4
5


means: "head the files '+2' and 'FILENAME'"


$ head -2 FILENAME
1
2

$ head -n 2 FILENAME
1
2

$ head -n +2 FILENAME
1
2


all mean: "show the first 2 lines of FILENAME"


$ head -n -2 FILENAME
1
2
3


means "show all BUT the last 2 lines of FILENAME"


$ tail +2 FILENAME
tail: Warning: "+number" syntax is deprecated, please use "-n +number"
2
3
4
5


means "I'm being too lazy to use -n, but show me FILENAME from line 2 down"


$ tail -2 FILENAME
4
5

$ tail -n 2 FILENAME
4
5

$ tail -n -2 FILENAME
4
5


mean "Show me the last 2 lines of FILENAME"


$ tail -n +2 FILENAME
2
3
4
5


means "Show me FILENAME from line 2 down"

Wednesday, February 18, 2009

vi - delete all matching lines...

:%g/^sometext,/ d

search range (all lines) : %
beginning with "sometext,
execute the Ex cmd "d" ; delete the line

Thought for the day...

People that call it V I instead of "vie"...

...probably don't need a "vi quick reference guide/cheatsheet" anyway.

:o)

Tuesday, February 17, 2009

Add correct host key in /home/john/.ssh/known_hosts to get rid of this message.


john@hostname:~/.ssh$ ssh user@hostname
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: POSSIBLE DNS SPOOFING DETECTED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
The RSA host key for hostname has changed,
and the key for the according IP address 123.45.67.89
is unknown. This could either mean that
DNS SPOOFING is happening or the IP address for the host
and its host key have changed at the same time.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
01:23:45:67:89:ab:cd:ef:fe:dc:ba:98:76:54:32:10.
Please contact your system administrator.
Add correct host key in /home/john/.ssh/known_hosts to get rid of this message.
Offending key in /home/john/.ssh/known_hosts:9
RSA host key for hostname has changed and you have requested strict checking.
Host key verification failed.


The known_hosts file is now encrypted, which makes it harder to find the bad line...
but you will note the line that says:

Offending key in /home/john/.ssh/known_hosts:9

(where :9 means line 9)

If you comment out or remove the line that the error indicates, this should fix the problem.

Alternatively, you can remove an entry for a given host using:


$ ssh-keygen -R hostname


Or find it with:


$ ssh-keygent -F hostname

Thursday, February 12, 2009

find grep hack to show name and content...

For a long time I've done things like:


for FILE in $(find * -type f -exec grep -l "$STRING" {} \;)
do
echo -n "$FILE"
grep -n "$STRING" $FILE
done


to get both the filename and the string it's matching on because there's no "name plus match" flag for grep... you either have -l or -n but not together...

I had a brainwave just now...

If you give grep more than one file to grep in - it tells you which file it found the match in... so how about:


$ find * -type f -exec grep -n $STRING {} /dev/null \;
path/to/the/FILE:12:I found $STRING on line 12!


If you can't be bothered typing, it can be any valid filename instead of /dev/null - i.e.:


grep -n $STRING {} /
grep -n $STRING {} .
grep -n $STRING {} *


I just figured /dev/null should hopefully have the least overhead to stat.

Be careful you don't give it an invalid filename or you'll get an error for each file the find finds!


$ find * -type f -exec grep STRING {} no_such_file \;
grep: no_such_file: No such file or directory
grep: no_such_file: No such file or directory
grep: no_such_file: No such file or directory
grep: no_such_file: No such file or directory
grep: no_such_file: No such file or directory