Statistiques
| Révision :

root / bin / get-disk-info @ 27

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

1
#!/bin/bash
2
SMARTTOOL="/usr/sbin/smartctl"
3

    
4

    
5

    
6
function usage {
7
  echo "Syntax :"
8
  echo "$0 -d device_name"
9
}
10

    
11
function nointeractive {
12

    
13
FIRST_TEST=$($SMARTTOOL $DEVBYID)
14
if [ $? -eq 0 ]
15
then
16
   while read line
17
   do
18
    if [[ "$line" =~ ":" ]]
19
    then
20
       echo $line
21
    fi 
22

    
23
   done <<< "$($SMARTTOOL -i -H $DEVBYID)"
24
   DEVBYIDNOPART=$(echo $DEVBYID |sed -e "s/\/dev\/disk\/by-vdev\///g" |sed -e "s/-part1$//g")
25
   if [ "$DEVBYIDNOPART" == "" ]
26
   then
27
        DEVBYIDNOPART=$(echo $DEVBYID |sed -e "s/\/dev\/disk\/by-id\///g" |sed -e "s/-part1$//g")
28
   fi
29
   echo "nameinzpool:$DEVBYIDNOPART"
30
   errorread=$(/sbin/zpool status |grep "$DEVBYIDNOPART"|sed -e "s/\t//g" |sed -e "s/ \+/ /g" | sed -e "s/^ //g"|cut -d " " -f3)
31
   echo "errorread:$errorread"
32
   errorwrite=$(/sbin/zpool status |grep "$DEVBYIDNOPART"|sed -e "s/\t//g" |sed -e "s/ \+/ /g" | sed -e "s/^ //g"|cut -d " " -f4)
33
   echo "errorwrite:$errorwrite"
34
   errorchecksum=$(/sbin/zpool status |grep "$DEVBYIDNOPART"|sed -e "s/\t//g" |sed -e "s/ \+/ /g" | sed -e "s/^ //g"|cut -d " " -f5)
35
   echo "errorchecksum:$errorchecksum"
36
   exit 0
37
fi
38

    
39
if [[ -e /sbin/multipath ]] || [[ -e /usr/sbin/multipath ]] || [[ -e /usr/local/sbin/multipath ]]
40
then
41

    
42
    resultMulti=$(multipath -v 2 -l $DEVBYID |sed -e 's/(/disk_id=/g' |sed -e 's/)//g'|cut -d " " -f2 |grep disk_id|cut -d '=' -f2)
43
    if [ "$resultMulti" != ""  ]
44
    then
45
        while read liner
46
        do
47
          if [[ "$liner" =~ ":" ]]
48
          then
49
              echo $liner
50
          fi 
51
        done<<< "$($SMARTTOOL -i -H /dev/disk/by-id/scsi-$resultMulti)"
52
        DEVBYIDNOPART=$(echo $DEVBYID|cut -d "/" -f4)
53
        echo "nameinzpool:$DEVBYIDNOPART"
54
        errorread=$(/sbin/zpool status |grep "$DEVBYIDNOPART "|sed -e "s/\t//g" |sed -e "s/ \+/ /g" | sed -e "s/^ //g"|cut -d " " -f3)
55
        echo "errorread:$errorread"
56
        errorwrite=$(/sbin/zpool status |grep "$DEVBYIDNOPART "|sed -e "s/\t//g" |sed -e "s/ \+/ /g" | sed -e "s/^ //g"|cut -d " " -f4)
57
        echo "errorwrite:$errorwrite"
58
        errorchecksum=$(/sbin/zpool status |grep "$DEVBYIDNOPART "|sed -e "s/\t//g" |sed -e "s/ \+/ /g" | sed -e "s/^ //g"|cut -d " " -f5)
59
        echo "errorchecksum:$errorchecksum"
60
        exit 0
61
    fi
62
fi
63

    
64
echo "no informations disk"
65
}
66

    
67
while getopts "d:h" OPTION
68
do
69
     case $OPTION in
70
         h)
71
             usage
72
             exit 1
73
             ;;
74
         d)
75
            DEVBYID=$OPTARG
76
            ;;
77
         *)
78
           usage
79
           exit 1
80
           ;;
81
     esac
82
done
83
if [[ -z $DEVBYID ]] 
84
then
85
     usage
86
     exit 1
87
fi
88

    
89
nointeractive
90