Skip to Content

Automated shutdown paranoid edition

Written on October 30, 2011 at 4:51 pm, by

One time I relied heavily on the ntfs-3g driver and it killed my ntfs-partition. Since then I always check if any mounted ntfs partition is umounted properly. For automation here is a code snippet for debian (ubuntu?). If a mount point in /media cannot be unmounted there will be no shutdown.

for f in `mount | grep /media/ | awk '{ print $1; }'`;
do 

! umount $f && exit

done

shutdown -h 1

Nice and proper shutdown of a program via console

Written on October 28, 2011 at 3:03 pm, by

Ever wanted to shutdown a program over the console just like you would close it normally over its GUI?

#example: transmission (bittorrent client) is able to
#report its upload stats to the tracker before
#shutdown this way

kill -2 `pidof transmission`

Reset a network-manager pptp vpn connection

Written on October 17, 2011 at 7:10 pm, by

Basic disconnect connect bash:

#!/bin/bash
CON=[insert your nm vpn connection id here]

nmcli con down uuid $CON
sleep 4s
nmcli con up uuid $CON

Get your connection id:

nmcli con list

HOWTO: Tell Grub to load windows 7 as default (debian)

Written on October 12, 2011 at 2:31 pm, by

… is quite easy if you know what to do (and it’s update safe!):

Only precondition: win7 or any other OS you want to boot as default is the next OS after the standard debian entries in the grub list / win7 is the only other OS installed

1. Edit /etc/default/grub

#find&edit or add if it doesn't exist
GRUB_DEFAULT=`/bin/bash "/somedir/getlastboot.sh"`

2. in /somedir/ create a getlastboot.sh with the following content

#!/bin/bash

VAR1=`ls -l /boot | grep -v .bak | grep -c initrd.img`
VAR2=`ls -l /boot | grep -v .bak | grep -c vmlinuz`

let DEFAULTX=VAR1+VAR2
echo $DEFAULTX

3. make it executable

chmod 777 getlastboot.sh

4. update-grub

sudo update-grub

(I have not tested it on ubuntu, but it should work there too)

S-ATA cables – more guilty than you might think

Written on July 17, 2011 at 6:21 pm, by

If you get sth. like this (and best case your raid 1 goes crazy)

daywalker kernel: [  498.324514] ata5.00: status: { DRDY }
[  498.324516] ata5.00: failed command: WRITE FPDMA QUEUED
[  498.324520] ata5.00: cmd 61/60:e8:e2:7d:0e/01:00:9c:00:00/40 tag 29 ncq 180224 out
[  498.324520]          res 50/00:d8:7a:87:0f/00:00:9c:00:00/40 Emask 0×10 (ATA bus error)
[  498.324522] ata5.00: status: { DRDY }
[  498.324524] ata5.00: failed command: WRITE FPDMA QUEUED
[  498.324527] ata5.00: cmd 61/88:f0:4a:7f:0e/01:00:9c:00:00/40 tag 30 ncq 200704 out
[  498.324528]          res 50/00:d8:7a:87:0f/00:00:9c:00:00/40 Emask 0×10 (ATA bus error)
[  498.324530] ata5.00: status: { DRDY }
[  498.324533] ata5: hard resetting link
[  498.644016] ata5: SATA link up 3.0 Gbps (SStatus 123 SControl 300)
[  498.646630] ata5.00: configured for UDMA/133
[  498.660052] ata5: EH complete
[  499.755828] ata5.00: exception Emask 0×10 SAct 0x7ffff9ff SErr 0×400100 action 0×6 frozen
[  499.755831] ata5.00: irq_stat 0×08000000, interface fatal error
[  499.755834] ata5: SError: { UnrecovData Handshk }
[  499.755836] ata5.00: failed command: WRITE FPDMA QUEUED
[  499.755840] ata5.00: cmd 61/00:00:b2:51:ed/04:00:4d:00:00/40 tag 0 ncq 524288 out
[  499.755840]          res 50/00:98:ba:6a:ed/00:01:4d:00:00/40 Emask 0×10 (ATA bus error)
[  499.755842] ata5.00: status: { DRDY }
[  499.755844] ata5.00: failed command: WRITE FPDMA QUEUED
[  499.755848] ata5.00: cmd 61/08:08:b2:55:ed/02:00:4d:00:00/40 tag 1 ncq 266240 out
[  499.755848]          res 50/00:98:ba:6a:ed/00:01:4d:00:00/40 Emask 0×10 (ATA bus error)
[  499.755850] ata5.00: status: { DRDY }

you might want to check a different S-ATA cable first. (Chances for a kernel bug are very bad too…) Would have spared me a lot of time… If you have got the opinion that the cable is innocent because windows is working properly on the same hdd well guess again because windows easily ships around this mess by falling back into not using dma :)

(If another cable on another SATA connector does not change anything the hdd is probably broken)

UPDATE:
http://lime-technology.com/wiki/index.php?title=The_Analysis_of_Drive_Issues
is pretty informative though!

UPDATE II:
Had a short conversation with a computer shop owner the other day. He told me that the SATA cables provided (for free) with the mainboard are much more likely to fail than others. Don’t know if he just wanted me to buy more cables (i did not) but my faulty one was indeed provided with the mainboard and he didn’t knew that in advance.

Unzip broken archive (partially)

Written on February 4, 2011 at 12:03 pm, by

Many solutions I found included wine and winrar (and this does not worked for me in any case btw). But I found sth different. (apt-)get (install) bsdtar!

bsdtar xf yourbrokenzip.zip

Besides for rar files the non free version does this like a charm

unrar -kb x yourrar.rar

Remember: These cmds do not repair anything. They just extract what they can!

backup exaile 0.3.2.0

Written on December 8, 2010 at 3:06 pm, by

“Three dirs man” THREE o.0

~/.cache/exaile
~/.config/exaile
~/.local/share/exaile

Howto Flash your BIOS the quick and dirty way

Written on October 7, 2010 at 5:05 pm, by

I never really understood why you should always get a bootdisc environment for flashing your motherboard bios. Flashing a bios takes few seconds including the verification of the written data. Why should a stable system fail right in this moment? Yeah this could fuck the whole system up but who tells you you got a secure power supply in case you use a bootable environment from a CDROM? So I went another way. Without creating a bootable cd. So…

What to do

  1. Flashing your BIOS is dangerous. You do anything at your own risk. Don’t flash your bios if everything works or you don’t know what you’re actually doing.
  2. Obtain flashrom (apt-get install flashrom)
  3. Check if your motherboard is supported. (chances are good)
    sudo -s
    flashrom -L
  4. Obtain the right (the one for your motherboard) bios image from your vendor
  5. If you made important modifications in your bios settings (overclock?) write them down. All your settings (including saved ones) will probably disappear with the update)
  6. IF you’re completely sure you got the right bios image for updating AND you made sure flashrom is about to update your motherboard bios and not sth else OTHERWISE check below
    sudo -s
    flashrom -w yourimage

    Check the programs output. Don’t reboot if it tells you sth went wrong badly!

  7. If everything worked. Reboot and reconfigure your bios settings.

How do I know I got the right image and flashrom will flash the motherboard bios?

  1. Obtain the current bios of your motherboard.
    sudo -s
    flashrom -r readbios
  2. If you know or you are able to guess your bios version obtain the outdated version you currently use from your vendor too.
  3. Check wether all images have the same size.
  4. Obtain vbindiff (apt-get install vbindiff) and check the hexdata DON’T EDIT ANYTHING
    vbindiff readbios unmodified_outdated_same_v_from_vendor

    If there’s a lot (!) different this is not your bios. (Some differences occour because all your settings probably are saved there too.) To see “a lot” compare your bios with the one you want to replace it with (the new). There should be much more difference.

    vbindiff readbios newbios

    My biosimages all have a date at the end which I could see in the hexeditor. If you have that too, check it! The bios you read from your motherboard and the outdated from your vendor should have the same date. The new image should have a newer date at exactly the same place.

  5. So if the filesize does not differ, you got a date in your hexfile and you’ve read Nr. 4 carefully you should have the right bios and flashrom should write it to the right flashmemory (the one of your motherboard).

unrarall

Written on May 15, 2010 at 12:26 pm, by

I’ve written a tool for unrar extraction in python. Basically you can feed it with *.rar and it will do the rest for you. Additionally it can perform cleanup after a successful extraction including a working partYX.rar detection and it’s got passwordfile support. For usage use -h

For install make it executable and put it into /usr/bin or wherever you like.

Depends on:

  • Unrar (non-free-version) 3.80
  • Python

Download it here:

http://unrarallpy.sourceforge.net/

or (maybe outdated)

http://cli-apps.org/content/show.php/Unrarall?content=124772

Nautilus – Empty Dir Script

Written on December 8, 2009 at 3:37 pm, by

“What does this do?” It sucks in air!

  • Tries to move all files out of the marked folder
  • Tries to remove the (now empty) dir
  • [If something cannot be done (no sufficent rights, file already exists, directory could not be emptied) it won't (should not) do it]

Its released under the GPLv2. Use it at your own risk. There should be no dataloss (except the marked directory itself) because all used commands take care of remaining (already existing) files.

#!/bin/bash

SAVEIFS=$IFS
IFS=$(echo -en "nb")

FILES=${NAUTILUS_SCRIPT_SELECTED_FILE_PATHS}

for FILE in ${FILES} ; do
    if [ -d ${FILE} ]; then
             cd "${FILE}"
             mv -n * ..
             cd ..
             rmdir "${FILE}"
    fi
done

IFS=$SAVEIFS

Have fun!

FAQ nautilus scripts (http://g-scripts.sourceforge.net/faq.php)