Schlagwort-Archive: bash

Raspberry Pi reset wireless lan to solve problems with no connection

I found a script on http://askubuntu.com/a/593589 which tried to reset the wlan interface in various ways. I modified that script a little with and installed in on cron and let it execute each minute (*/1 * * * * /root/bin/resetWifi.sh)

resetWifi.sh:


#!/bin/bash
# program to check wifi and reset if not running
if [[ ! -z "$(ps waux | grep $0)" ]]; then exit 0; fi
exec 2>&1 1> >(tee -a $HOME/wificheck.log)
GATEWAY=192.168.1.1
IWCONFIG_BIN=$(which iwconfig)
RFKILL_BIN=$(which rfkill)
PING_BIN=$(which ping)
DEVICE=$(iwconfig 2>/dev/null | grep 802 | awk '{print $1}')
function isPingWorking {
        if ${PING_BIN} -c 1 ${GATEWAY} >/dev/null 2>&1 ; then
                exit 0
        else
                echo "didn't work :("
        fi
}
while true; do
        isPingWorking
        # Failed, try to reset wifi - sometimes works ok
        date
        ifdown ${DEVICE}
        sleep 1
        ifup ${DEVICE}
        sleep 10
        isPingWorking
        echo "turn wlan stick power off... "
        ${IWCONFIG_BIN} ${DEVICE} txpower off
        sleep 3
        ${IWCONFIG_BIN} ${DEVICE} txpower auto
        isPingWorking
        echo "use rfkill to reenable wlan stick... "
        ${RFKILL_BIN} list
        ${RFKILL_BIN} block wifi
        sleep 3
        ${RFKILL_BIN} unblock wifi
        isPingWorking
done
exit 0

Test if you have rfkill installed. The other bins should be available on most default installations.

Verschiedene Webradios nach x Tagen durchwechseln

Da ich gerne auch lokal die Musik habe, die auf dem von mir gekauften Radiostream läuft lass ich ein Skript laufen, dass nach 2 Tagen rippen zur nächsten Station wechselt und wiederum 2 Tage rippt. Sind alle Stationen durch wird von vorne begonnen. Wird dem Skript als Argument eines der Stichworte für ein bestimmtes Radio übergeben, fängt das rippen bei diesem Radio an.

Hier das Skript:

<pre>#!/bin/bash
DI_FM_FOLDER=/path/to/folder

if [ ! -z "$1" ]; then
        STREAM_TO_PLAY=$1
fi

function startRipping {
        # kill the running streamripper
        killall streamripper
        # lets safe the unix epoch time when the recording starts
        # we use that for calculating how long the webradio recording is running
        STARTTIME=`date +%s`
        echo "currently ripping $1"
        $DI_FM_FOLDER/$1.sh
        # as long as the startdate is greater than the current date minus 2 days the stream is executed
        while true; do
                if [ ! $STARTTIME -ge $(date +%s -d "-2 days") ];then
                        break;
                fi
                sleep 1
        done
}

# if the for loop inside the while exits, it starts again at the beginning (aka endless loop)
while true; do
        # process all the streams 2 days each
        for i in liquid progressive techno minimal psychill chillout trance goa; do
                # if this script is started with an argument, the var $STREAM_TO_PLAY is not empty and it will start
                # the ripping cicle with that stream and skips the ones before it. if it's started at the right point
                # it will set the $STREAM_TO_PLAY far to a empty string and normal ripping can proceed.
                if [ ! -z $STREAM_TO_PLAY ]; then
                        if [ $i == $STREAM_TO_PLAY ];then
                                startRipping $i
                                unset STREAM_TO_PLAY
                        fi
                else
                        startRipping $i
                fi
        done
done</pre>

Im startRipping ist dann nur eine case Kontrollstruktur für jeden einzelnen Radiostream und die jeweilige Radio-IP.