Posts Tagged ‘scripts’

Router reboot wrapper script

This is a memory sink article. I found this nice python script which reboots a B525 router and wanted to write a wrapper script around it.


# refs:,

RUNDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"


if [ -f $LOCK_FILE ]; then
    echo "Already running, exiting"
    exit -1

function finish {
  rm $RUNDIR/lock
trap finish EXIT

touch $RUNDIR/lock

while (( $ATTEMPT < $MAX_ATTEMPTS ))
    DATE=$(date +%Y%d%m-%H%M%S)
    echo -e "GET http://$REMOTE HTTP/1.0\n\n" | nc $REMOTE 80 > /dev/null 2>&1

    if [ $? -eq 0 ]; then
        echo "$DATE: Online"
        ping -c1 -w1 LOCAL > /dev/null 2>&1

        if [ $? -eq 0 ]; then
            echo "$DATE: Internet offline, router online, trying to reboot router, waiting $TIMEOUT"
            echo "$DATE: Internet offline, router offline, waiting $TIMEOUT"

        sleep $TIMEOUT
        ATTEMPT=$(( ATTEMPT + 1 ))
        TIMEOUT=$(( TIMEOUT * 2 ))


After spending loosing time in vain trying to convert kml files containing the gx:Track format to gpx files for my gps and finally writing my own tool for doing that I realized I have done quite a lot of small scripts for gps data manipulation and decided to push them on github. I started with 2 and as I will clean the others I will push them also.


A set of python scripts to manipulate GPS data

Removes TimeStamp information from .kml files. More precisely, it removes gx:TimeStamp and //kml:Placemark/kml:TimeStamp elements. Modifies the document in place. file.kml

Converts kml gx:Track to old style LineString elements. This is required because not even gpsbabel can convert the gx:Track elements to gpx for instance resulting in data loss. Conversion is done in place. file.kml


CD backup

Since my last laptop with a working CD drive is dying this a simple script which does the following ops once the CD is inserted and auto-mounter:

  • finds the mount point
  • copies the files
  • ejects the CD
cd "$(cat /proc/mounts | grep iso9660 | cut -d' ' -f2 | sed -e 's#\\040# #g')" 
&& cp * /media/backup/data/ && cd && eject /dev/sr0

Archive all files modified in the last 24h

find . -mtime 1 -type f -print0 | tar -czvf $SYNC_DIR/$BFILE -T - --null

Checking badblocks with smartmontools

… and some other observations. Warning: use at your own risk!

I used to keep some of my photo backups on an external Seagate 500G drive which I also use for travel. Today however as I tried to access it I noticed some problems so I quickly ran:

smartctl -t long /dev/sdb
#followed by
smartctl -l selftest
#the result
Extended offline    Completed: read failure       90%       109         414996448 (more…)