-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfptransfer.sh
More file actions
executable file
·78 lines (67 loc) · 1.71 KB
/
fptransfer.sh
File metadata and controls
executable file
·78 lines (67 loc) · 1.71 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
# check,create,chown,chmod,and mv file when transfer source dir to destination dir
if [[ $# != 1 ]] ; then
echo "Usage:bash $0 listfile"
exit 1
else
read -n1 -p "Moving files in $1 (Y/N):" input
case $input in
Y|y)
echo -e "\n OK!";;
N|n)
echo -e "\nExit";
exit 1;;
*)
echo -e "\nIncorrect input";
exit 2;;
esac
fi
logfile=./transfer.log
mvuser=imgo
mvgroup=imgo
filelist=$1
if [[ ! -f $filelist ]] ; then
echo "Filelist not exists "
exit 1
else
id $mvuser &> /dev/null
if [[ $? -ne 0 ]] ; then
echo "User $mvuser not exists"
exit 1
fi
fi
[ -e $logfile ] && echo > $logfile
date >> $logfile
cat "$filelist" | while read sourcefilename destfilename
do
destfiledir=`dirname "$destfilename"`
if [[ ! -d "$destfiledir" ]] ; then
mkdir -p "$destfiledir"
if [[ $? -ne 0 ]]; then
echo "Failed to mkdir $destfiledir"
exit 1
fi
chown ${mvuser}:${mvgroup} "$destfiledir"
if [[ $? -ne 0 ]]; then
echo "Failed to chown for $destfiledir"
exit 1
fi
fi
if [[ -e "$sourcefilename" ]] ; then
mv "$sourcefilename" "$destfilename"
if [[ $? -ne 0 ]]; then
echo "Failed to mv from $sourcefilename to $destfilename"
exit 1
fi
chown ${mvuser}:${mvgroup} "$destfilename"
if [[ $? -ne 0 ]]; then
echo "Failed to chown for $destfilename"
exit 1
fi
echo "$sourcefilename moved"
else
echo "$sourcefilename not exists"
exit 1
fi
done &>>$logfile
date >> $logfile