Bash scripting problem

Posted by komidore64 on Stack Overflow See other posts from Stack Overflow or by komidore64
Published on 2010-05-09T06:30:35Z Indexed on 2010/05/09 6:38 UTC
Read the original article Hit count: 615

Filed under:
|
|

I'm writing a bash script to sync my iTunes music directory to a directory on a removable hard drive. The script works fine when there is absolutely nothing in the folder on the external hard drive. Once all files have been copied to the external drive, then the script begins to act strange. Even though i just sync'd everything over, it proceeds to recopy certain files again. After the initial sync, it chooses the same files to resync each consecutive time the script is executed without any changes being made to the source directory.

#!/bin/bash
# shell script to sync music with gigabeat and/or firewire drive

musicdir="/Users/komidore64/Music/iTunes/iTunes Media/Music"
gigadir="/Volumes/GIGABEAT/music"
# fwdir="/Volumes/"

remove() {
    find "$1" \
        ! \( -name "*.wav" \
        -o -name "*.ogg" \
        -o -name "*.flac" \
        -o -name "*.aac" \
        -o -name "*.mp3" \
        -o -name "*.m4a" \
        -o -name "*.wma" \
        -o -name "*.m4p" \
        -o -name "*.ape" \
        -o -type d \) \
        -exec rm -i {} \;
}


if [ $# == 0 ]; then
    echo "no device argument present"
    echo "specify '-g' for gigabeat"
    echo "or '-f' for firewire drive"
else
    remove "$musicdir"
    while [ $1 ]; do
        case $1 in
            -g | --gigabeat )   rsync --archive --verbose --delete "$musicdir/" "$gigadir"
                                ;;
            -f | --firewire )   rsync --archive --verbose --delete "$musicdir/" "$fwdir"
        esac
        shift
    done
    echo "music synced"
fi

© Stack Overflow or respective owner

Related posts about bash

Related posts about synchronization