-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhosts.sh
90 lines (83 loc) · 1.41 KB
/
hosts.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
#!/bin/bash
send_keys(){
OLDIFS=$IFS
IFS=";"
while read host un ip
do
if [[ "$host" =~ ^#.* ]]; then
continue
fi
echo $host
ssh-copy-id -i ./thkey.pub $un@$ip
done < "./hosts.csv"
IFS=$OLDIFS
}
send_file(){
OLDIFS=$IFS
IFS=";"
while read host un ip
do
if [[ "$host" =~ ^#.* ]]; then
continue
fi
echo $host
IP=$(./hosts.sh ${host})
UN=$(./hosts.sh ${host} un)
PW=$(./hosts.sh ${host} pw)
sshpass -p ${PW} scp -o StrictHostKeyChecking=no $1 $UN@${IP}:/tmp/
done < "./hosts.csv"
IFS=$OLDIFS
}
send_cmd(){
OLDIFS=$IFS
IFS=";"
while read host un ip
do
if [[ "$host" =~ ^#.* ]]; then
continue
fi
echo $host : $1
IP=$(./hosts.sh ${host})
UN=$(./hosts.sh ${host} un)
PW=$(./hosts.sh ${host} pw)
OUT=$(sshpass -p ${PW} ssh -n -o StrictHostKeyChecking=no $UN@${IP} -C $1)
echo $OUT
done < "./hosts.csv"
IFS=$OLDIFS
}
get_ip(){
OLDIFS=$IFS
IFS=";"
while read host un pw ip
do
if [[ "$host" =~ ^#.* ]]; then
continue
fi
#echo $host
if [ "$1" == "$host" ]
then
if [ "$2" == "un" ]; then
echo $un
exit 0
elif [ "$2" == "pw" ]; then
echo $pw
exit 0
else
echo $ip
exit 0
fi
fi
done < "./hosts.csv"
echo "Not Found"
exit 1
IFS=$OLDIFS
}
if [ "$1" == "keys" ]; then
send_keys
elif [ "$1" == "send" ]; then
send_file $2
elif [ "$1" == "cmd" ]; then
send_cmd "$2"
else
get_ip $1 $2
fi