Statistiques
| Révision :

root / bin / get-conf-iscsi-volume @ 39

Historique | Voir | Annoter | Télécharger (2,69 ko)

1
#!/bin/bash
2
# $Id: get-conf-iscsi-volume 39 2013-10-08 12:46:21Z ltaulell $
3

    
4
if [ "$1" == "" ]
5
then
6
   echo "Syntax : $0 path_dev"1>&2
7
   exit 1;
8
fi
9
TID_ISCSI=$(cat /proc/net/iet/volume |grep -B1 "$1$" |grep "tid" |awk '{split($0,array,"tid:")} END {print array[2]}'|cut -d " " -f1)
10
if [ "$TID_ISCSI" == "" ]
11
then
12
  echo "Device not found $TID_ISCSI"
13
  exit 0
14
fi
15
COPY_LINE=1
16
TARGET=$(cat /proc/net/iet/session |grep tid:$TID_ISCSI |awk '{split($0,array,"name:")} END {print array[2]}') 
17
LUN=$(cat /proc/net/iet/volume |grep "tid:$TID_ISCSI" -A1  | awk '{split($0,array,"lun:")} END {print array[2]}'|cut -d " " -f1)
18
TYPE=$(cat /proc/net/iet/volume |grep "tid:$TID_ISCSI" -A1  | awk '{split($0,array,"iotype:")} END {print array[2]}'|cut -d " " -f1)
19
DEV_PATH=$(cat /proc/net/iet/volume |grep "tid:$TID_ISCSI" -A1  | awk '{split($0,array,"path:")} END {print array[2]}'|cut -d " " -f1)
20

    
21
echo "tid $TID_ISCSI"
22
echo "target $TARGET"
23
echo "lun $LUN"
24
echo "exportType $TYPE"
25
echo "devPath $DEV_PATH"
26
COPY_LINE=0
27
while read line
28
do
29
  SEARCH_TARGET=$(echo $line |grep -i "^Target")
30
  if [ "$SEARCH_TARGET" != "" ]
31
  then
32
     COPY_LINE=0
33
  fi
34
  SEARCH_MYTARGET=$(echo $line |grep -i "^Target $TARGET")
35
  if [ "$SEARCH_MYTARGET" != "" ]
36
  then
37
     COPY_LINE=1
38
  fi
39
  if [ $COPY_LINE -eq 1 ]
40
  then
41
     SEARCH_USER=$(echo $line |grep -i "^IncomingUser")
42
     if [ "$SEARCH_USER" != "" ]
43
     then
44
        USERCHAP=$(echo $SEARCH_USER|cut -d " " -f2)
45
        PASSCHAP=$(echo $SEARCH_USER|cut -d " " -f3)
46
        if [ "$USERCHAP" != "IncomingUser" ]
47
        then
48
           echo "login $USERCHAP"
49
           echo "passwd $PASSCHAP"
50
        fi
51
     fi 
52
   fi
53

    
54
done < "/etc/iet/ietd.conf"
55

    
56

    
57
COPY_LINE=0
58
while read line
59
do
60
  SEARCH_TID=$(echo $line |grep -i "^tid")
61
  if [ "$SEARCH_TID" != "" ]
62
  then
63
     COPY_LINE=0
64
  fi
65
  SEARCH_MYTID=$(echo $line |grep -i "^tid:$TID_ISCSI ")
66
  if [ "$SEARCH_MYTID" != "" ]
67
  then
68
     COPY_LINE=1
69
  fi
70
  if [ $COPY_LINE -eq 1 ]
71
  then
72
     SEARCH_SID=$(echo $line |grep -i "sid:"| awk '{split($0,array,"sid:")} END {print array[2]}'|cut -d " " -f1)
73
     if [ "$SEARCH_SID" != "" ]
74
     then
75
        SESSION_IP=$(cat /proc/net/iet/session |grep "sid:$SEARCH_SID" -A1  | awk '{split($0,array,"ip:")} END {print array[2]}'|cut -d " " -f1)
76
        if [ "$SESSION_IP" != "" ]
77
        then
78
           echo "sid $SEARCH_SID"
79
           echo "sessionIP $SESSION_IP"
80
        fi
81
     fi 
82
   fi
83

    
84
done < "/proc/net/iet/session"
85

    
86
allowIP=""
87
while read line
88
do
89
  SEARCH_MYTARGET=$(echo $line |grep -i "$TARGET")
90
  if [ "$SEARCH_MYTARGET" != "" ]
91
  then
92
     if [ "$allowIP" == "" ]
93
     then
94
        allowIP=$(echo $SEARCH_MYTARGET |cut -d " " -f2)
95
     else
96
        allowIP=$allowIP";"$(echo $SEARCH_MYTARGET |cut -d " " -f2)
97
     fi
98
  fi
99
done < "/etc/iet/initiators.allow"
100
echo "allowIP $allowIP"