summaryrefslogtreecommitdiff
path: root/cpflat.sh
blob: 0092ea4d29199b087bb330202009f265e133632e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/sh

IFS='
'
_=$(basename $0)

if [ "x$1" == "x-r" ] ; then
    RENAME=y
    shift
fi

if [ -z "$2" ] ; then
    echo $_: usage $_ [-r] scp_destination extension
    exit 1
fi

DEST=$1
EXT=$2

flist=$(find . -type f -iname "*.$EXT")

for i in $flist ; do
    dir=$(dirname "$i")
    last_dir=$(basename "$dir")

    if [ -z "$last_dir" ] ; then
    	last_dir=$dir
    fi

    fname=$(basename "$i")

    if [ "$RENAME" ] ; then
    	fname="$last_dir.$EXT"
    fi

    if ! scp "$i" "$DEST/$fname" ; then
    	echo $_: Copy failed
	exit 1
    fi
done