#!/bin/sh # # Find MP3 files # cmd=$(basename $0) hosts=$(cat ~/.mp3findrc) usage() { if [ $1 -eq 1 ]; then echo "usage: $cmd [-d] [-p] host [pattern] type \`$cmd -h' for help" >&2 else echo "usage: $cmd [-d] [-p] host [pattern] options: -d search for directories -p match the full path" fi exit $1 } type=f while getopts ":dph" c do case "$c" in d) type=d;; p) fullpath=1;; h) usage 0;; :|'?') usage 1;; esac done shift $(($OPTIND - 1)) if [ $# -eq 0 ]; then usage 1; fi IFS=" " for host in $hosts; do if [ "${host%%#*}" = "" ]; then continue; fi alias=${host%%:*} if [ "$1" = "$alias" ]; then host=${host#*:}; hostname=${host%%:*} host=${host#*:}; path=${host%%:*} break fi done if [ -z "$hostname" ]; then echo "$cmd: No entry exists for host '$1'" exit 1 fi if [ $# -gt 1 ]; then if [ -n "$fullpath" ]; then param="-ipath '*$2*" else param="-iname '*$2*" fi if [ "$type" = "f" ]; then param="$param.[Mm][Pp]3'" else param="$param'" fi fi ssh $hostname "find '$path' $param -type $type -ls" | findfmt .