Raspberry Pi – script to dump raspivid video output to a file

  linux, raspberry-pi
#!/bin/bash
THEPATH=/mnt/d1
LIVEFILE=live
while true
do
        # if file exists, move it
        if [ ! -f $THEPATH/$LIVEFILE ]; then
            echo "ERROR: File not found so I can't move it fore you, at $THEPATH/$LIVEFILE"
        else
                mv $THEPATH/$LIVEFILE $THEPATH/`date +%Y.%m.%d_%H.%M.%S.h264`
        fi

        FREEMEGS=` df $THEPATH | awk '{print $2}' |  grep -v 1K-blocks `
        echo "Free megs: $FREEMEGS "
        # 5 gigs limit
        if [ $FREEMEGS -gt "5000000" ]
        then
                echo "Space OK"
                raspivid --nopreview --output - --timeout 3600000 --sharpness 100 --brightness 55 --vstab --bitrate 1500000 --width 1280 --height 720 > $THEPATH/$LIVEFILE
                # 30 seconds
                # raspivid --output - --timeout 30000 --sharpness 100 --brightness 55 --vstab --bitrate 1500000 --width 1280 --height 720 > $THEPATH/$LIVEFILE
        else
                echo "ERROR ERROR ERROR Running out of space" > ~/log.txt
                sleep 15
        fi
done