Nützliche Shell-Skripte

Im Laufe meiner Linux-User-Laufbahn hat sich so einiges an Skripten angesammelt, von denen ich hier eine Auswahl veröffentlichen möchte.
  1. Backup-Skript. Inkrementelles Backup mithilfe des Tools rsync. Siehe hier
  2. s.o., tägliche Sicherung des inkrementelles Backups. Siehe hier
  3. Finden vom toten symbolischen Links im Dateisystem
    #!/bin/bash
    if [ -z "$1" ] ; then
        echo "usage: $0 <directory>"
        exit 1
    fi
    for i in `find $1` ; do
        if [ -h $i ]
        then     
       	file $i | grep broken
        fi
    done
    
  4. Kopiere alle Dateien deren Namen in einer Hilfsdatei stehen von A nach B
    #!/bin/bash
    
    if [ -z $1 ] || [ -z $2 ] || [ -z $3 ] ; then
        echo "usage: $0 <filename-file> <start-search-dir> <copy-to-dir>"
        exit 1
    fi
    if [ ! -f $1 ] ; then
        echo "filename-file does not exist"
        exit 1
    fi
    if [ ! -d $2 ] ; then
        echo "start-search-dir does not exist or is no directory"
        exit 1
    fi
    if [ ! -d $3 ] ; then
        echo "copy-to-dir does not exist or is no directory"
        exit 1
    fi
    
    function findFile() {
        local FILE=$1
        local DIR=$2
        echo `find -L $DIR -iname $FILE`
    }
    
    function copyFile() {
        local FROM=$1
        local TO=$2
        cp -v "$FROM" "$TO"
    }
    
    echo "copy all files that are named in file $1 inside $2 to $3"
    while read LINE
    do
        FILE=`echo $LINE | tr -d '\r'`
        FOUND=`findFile $FILE $2`
        COUNT=`echo "$FOUND" | grep -o $2 | wc -w`
        if [ $COUNT -gt 1 ]; then
    	echo "too much search results to copy $FILE: $FOUND"
        elif [ $COUNT -lt 1 ]; then
    	echo "file not found $FILE"
        else
    	copyFile "$FOUND" "$3"
        fi
    done < $1