#!/bin/bash # this program may format you harddisk, frighten your cat or simply # do what you want - no warranties ################################################################### # # look for unlinked vdr recordings on secondary video-directory # ################################################################### # enter your primary video directory here VIDEO_DIR=/media/video0 ##################################################### # you may not want to change anything after this line #set -x unset LANG export LC_ALL=C VIDEO_BASE=$(echo $VIDEO_DIR | sed 's/[0-9]*$//') MARK_FILE=lostchk.vdr if [ "$VIDEO_DIR" == "$VIDEO_BASE" ]; then echo "$VIDEO_DIR is not base of a distributed video directory" exit 1 fi VIDEO_DIGITS=$(( ${#VIDEO_DIR} - ${#VIDEO_BASE} )) get_video_dir() { local INDEX="$1" local POSTFIX="000$INDEX" echo "$VIDEO_BASE${POSTFIX: $(( - $VIDEO_DIGITS )):$VIDEO_DIGITS}" } echo "prepeare" > /dev/stderr i=0 while [ -a "$(get_video_dir $i)" ]; do find "$(get_video_dir $i)" -name "$MARK_FILE" -exec rm -f {} \; i=$(( $i + 1 )) echo -n "." > /dev/stderr done echo > /dev/stderr echo "check recordings" > /dev/stderr while read DIR; do touch "$DIR/$MARK_FILE" REC_NAME="${DIR#$VIDEO_DIR}" REC_NAME="${REC_NAME#/}" i=1 while true; do REC="00$i" REC="${REC: -3:3}.vdr" REC_FILE="$DIR/$REC" if [ -e "$REC_FILE" ]; then if [ -h "$REC_FILE" ]; then LINK_DEST="$(readlink "$REC_FILE")" DEST_DIR="$(dirname "$LINK_DEST")" touch "$DEST_DIR/$MARK_FILE" fi else break; fi i=$(( $i + 1 )) done echo -n "." > /dev/stderr done < <(find "$VIDEO_DIR" -name "*.rec" -o -name "*.del") echo > /dev/stderr echo "find lost recordings" > /dev/stderr i=0 while [ -e "$(get_video_dir $i)" ]; do while read DIR; do if [ '!' -e "$DIR/$MARK_FILE" ]; then echo > /dev/stderr echo $DIR fi echo -n "." > /dev/stderr done < <(find "$(get_video_dir $i)" -name "*.rec" -o -name "*.del") i=$(( $i + 1 )) done echo > /dev/stderr echo "clean up" > /dev/stderr i=0 while [ -a "$(get_video_dir $i)" ]; do find "$(get_video_dir $i)" -name "$MARK_FILE" -exec rm -f {} \; i=$(( $i + 1 )) echo -n "." > /dev/stderr done echo > /dev/stderr