root / bin / get-conf-iscsi-volume @ 67
Historique | Voir | Annoter | Télécharger (2,82 ko)
1 |
#!/bin/bash |
---|---|
2 |
# $Id: get-conf-iscsi-volume 51 2013-10-10 11:20:37Z ltaulell $ |
3 |
# Copyright (C) 2013 Kevin Reverchon, Loïs Taulelle |
4 |
# This file/program is part of gZFS free software |
5 |
# See COPYING file for details |
6 |
# |
7 |
|
8 |
if [ "$1" == "" ] |
9 |
then |
10 |
echo "Syntax : $0 path_dev"1>&2 |
11 |
exit 1; |
12 |
fi |
13 |
TID_ISCSI=$(cat /proc/net/iet/volume |grep -B1 "$1$" |grep "tid" |awk '{split($0,array,"tid:")} END {print array[2]}'|cut -d " " -f1) |
14 |
if [ "$TID_ISCSI" == "" ] |
15 |
then |
16 |
echo "Device not found $TID_ISCSI" |
17 |
exit 0 |
18 |
fi |
19 |
COPY_LINE=1 |
20 |
TARGET=$(cat /proc/net/iet/session |grep tid:$TID_ISCSI |awk '{split($0,array,"name:")} END {print array[2]}') |
21 |
LUN=$(cat /proc/net/iet/volume |grep "tid:$TID_ISCSI" -A1 | awk '{split($0,array,"lun:")} END {print array[2]}'|cut -d " " -f1) |
22 |
TYPE=$(cat /proc/net/iet/volume |grep "tid:$TID_ISCSI" -A1 | awk '{split($0,array,"iotype:")} END {print array[2]}'|cut -d " " -f1) |
23 |
DEV_PATH=$(cat /proc/net/iet/volume |grep "tid:$TID_ISCSI" -A1 | awk '{split($0,array,"path:")} END {print array[2]}'|cut -d " " -f1) |
24 |
|
25 |
echo "tid $TID_ISCSI" |
26 |
echo "target $TARGET" |
27 |
echo "lun $LUN" |
28 |
echo "exportType $TYPE" |
29 |
echo "devPath $DEV_PATH" |
30 |
COPY_LINE=0 |
31 |
while read line |
32 |
do |
33 |
SEARCH_TARGET=$(echo $line |grep -i "^Target") |
34 |
if [ "$SEARCH_TARGET" != "" ] |
35 |
then |
36 |
COPY_LINE=0 |
37 |
fi |
38 |
SEARCH_MYTARGET=$(echo $line |grep -i "^Target $TARGET") |
39 |
if [ "$SEARCH_MYTARGET" != "" ] |
40 |
then |
41 |
COPY_LINE=1 |
42 |
fi |
43 |
if [ $COPY_LINE -eq 1 ] |
44 |
then |
45 |
SEARCH_USER=$(echo $line |grep -i "^IncomingUser") |
46 |
if [ "$SEARCH_USER" != "" ] |
47 |
then |
48 |
USERCHAP=$(echo $SEARCH_USER|cut -d " " -f2) |
49 |
PASSCHAP=$(echo $SEARCH_USER|cut -d " " -f3) |
50 |
if [ "$USERCHAP" != "IncomingUser" ] |
51 |
then |
52 |
echo "login $USERCHAP" |
53 |
echo "passwd $PASSCHAP" |
54 |
fi |
55 |
fi |
56 |
fi |
57 |
|
58 |
done < "/etc/iet/ietd.conf" |
59 |
|
60 |
|
61 |
COPY_LINE=0 |
62 |
while read line |
63 |
do |
64 |
SEARCH_TID=$(echo $line |grep -i "^tid") |
65 |
if [ "$SEARCH_TID" != "" ] |
66 |
then |
67 |
COPY_LINE=0 |
68 |
fi |
69 |
SEARCH_MYTID=$(echo $line |grep -i "^tid:$TID_ISCSI ") |
70 |
if [ "$SEARCH_MYTID" != "" ] |
71 |
then |
72 |
COPY_LINE=1 |
73 |
fi |
74 |
if [ $COPY_LINE -eq 1 ] |
75 |
then |
76 |
SEARCH_SID=$(echo $line |grep -i "sid:"| awk '{split($0,array,"sid:")} END {print array[2]}'|cut -d " " -f1) |
77 |
if [ "$SEARCH_SID" != "" ] |
78 |
then |
79 |
SESSION_IP=$(cat /proc/net/iet/session |grep "sid:$SEARCH_SID" -A1 | awk '{split($0,array,"ip:")} END {print array[2]}'|cut -d " " -f1) |
80 |
if [ "$SESSION_IP" != "" ] |
81 |
then |
82 |
echo "sid $SEARCH_SID" |
83 |
echo "sessionIP $SESSION_IP" |
84 |
fi |
85 |
fi |
86 |
fi |
87 |
|
88 |
done < "/proc/net/iet/session" |
89 |
|
90 |
allowIP="" |
91 |
while read line |
92 |
do |
93 |
SEARCH_MYTARGET=$(echo $line |grep -i "$TARGET") |
94 |
if [ "$SEARCH_MYTARGET" != "" ] |
95 |
then |
96 |
if [ "$allowIP" == "" ] |
97 |
then |
98 |
allowIP=$(echo $SEARCH_MYTARGET |cut -d " " -f2) |
99 |
else |
100 |
allowIP=$allowIP";"$(echo $SEARCH_MYTARGET |cut -d " " -f2) |
101 |
fi |
102 |
fi |
103 |
done < "/etc/iet/initiators.allow" |
104 |
echo "allowIP $allowIP" |