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.

#!/bin/bash

# refs: https://github.com/jinxo13/HuaweiB525Router, https://github.com/mkorz/b618reboot

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

MAX_ATTEMPTS=10
ATTEMPT=0
TIMEOUT=60
LOCK_FILE=$RUNDIR/lock
REMOTE=google.com
LOCAL=192.168.7.1

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

function finish {
  rm $RUNDIR/lock
}
trap finish EXIT

touch $RUNDIR/lock

while (( $ATTEMPT < $MAX_ATTEMPTS ))
do
    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"
        break
    else
        ping -c1 -w1 LOCAL > /dev/null 2>&1

        if [ $? -eq 0 ]; then
            echo "$DATE: Internet offline, router online, trying to reboot router, waiting $TIMEOUT"
            $RUNDIR/b618reboot/reboot_router.py
        else
            echo "$DATE: Internet offline, router offline, waiting $TIMEOUT"
        fi

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

py-gps-tools

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.

py-gps-tools

A set of python scripts to manipulate GPS data

kmlCleanTimeStamp.py

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

kmlCleanTimeStamp.py file.kml

kmlTrack2LineString.py

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.

kmlTrack2LineString.py 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…)