-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsamba_copy.sh
executable file
·102 lines (84 loc) · 2.05 KB
/
samba_copy.sh
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/bash
#dirs to mount
local_dir_A="/mnt/local_dir_A"
remote_dir_A="C$/Archivos de programa/"
local_dir_B="/mnt/local_dir_B"
remote_dir_B="C$/Documents and Settings/All Users/Escritorio/"
#files or dir to copy
file_A="Nombre Equipo/"
file_B="All Users/Nombre Equipo.lnk"
#user auth
username=hpr/adalessandro
password=contraseña
#input/output files
INPUT=input.txt
OUTPUT=output.txt
#other parameters
TIMEOUT=3
IFS=","
process() {
echo "***************$HOSTNAME***************"
#mounting A
umount $local_dir_A
timeout $TIMEOUT smbmount "//$HOSTNAME/$remote_dir_A" "$local_dir_A" -o user=$username,password=$password
if [ "$?" -ne "0" ]; then
echo "smbmount_A failed" >> $OUTPUT
continue
fi
#mounting B
umount $local_dir_A
umount $local_dir_B
timeout $TIMEOUT smbmount "//$HOSTNAME/$remote_dir_B" "$local_dir_B" -o user=$username,password=$password
if [ "$?" -ne "0" ]; then
echo "smbmount_B failed" >> $OUTPUT
continue
fi
#copying A
cp -r "./$file_A" $local_dir_A
if [ "$?" -ne "0" ]; then
echo "cp_A failed" >> $OUTPUT
continue
fi
#copying B
cp -r "./$file_A" $local_dir_A
cp -r "./$file_B" $local_dir_B
if [ "$?" -ne "0" ]; then
echo "cp_B failed" >> $OUTPUT
continue
fi
#allright!
echo "OK" >> $OUTPUT
((count++))
}
# main
count=0
total=0
case "$1" in
status)
while read HOSTNAME STATUS
do
((total++))
case $STATUS in
OK) ((count++));;
*) continue;;
esac
done < $INPUT
echo "***************STATS***************"
echo "Total: $total"
echo "Total OK's: $count"
;;
run)
while read HOSTNAME STATUS
do
case $STATUS in
OK) echo "$HOSTNAME,$STATUS" >> $OUTPUT;;
*) echo -n "$HOSTNAME," >> $OUTPUT; process;;
esac
done < $INPUT
echo "***************STATS***************"
echo "Total new OK's: $count"
;;
*)
echo "Wrong. Options are: status|run"
;;
esac