Statistiques
| Révision :

root / bin / get-disk-info @ 64

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

1
#!/bin/bash
2
# $Id: get-disk-info 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
BINZFS="/sbin/zfs"
9
BINZPOOL="/sbin/zpool"
10

    
11
SMARTTOOL="/usr/sbin/smartctl"
12

    
13
function usage {
14
  echo "Syntax :"
15
  echo "$0 -d device_name"
16
}
17

    
18
function nointeractive {
19

    
20
FIRST_TEST=$($SMARTTOOL $DEVBYID)
21
if [ $? -eq 0 ]
22
then
23
   while read line
24
   do
25
    if [[ "$line" =~ ":" ]]
26
    then
27
       echo $line
28
    fi 
29

    
30
   done <<< "$($SMARTTOOL -i -H $DEVBYID)"
31
   DEVBYIDNOPART=$(echo $DEVBYID |sed -e "s/\/dev\/disk\/by-vdev\///g" |sed -e "s/-part1$//g")
32
  # echo "DEVBYIDNOPART= $DEVBYIDNOPART"
33
   if [[ "$DEVBYIDNOPART" == "" ]] || [[ "$DEVBYIDNOPART-part1" == "$DEVBYID" ]]
34
   then
35
        DEVBYIDNOPART=$(echo $DEVBYID |sed -e "s/\/dev\/disk\/by-id\///g" |sed -e "s/-part1$//g")
36
        echo "DEVBYIDNOPART= $DEVBYIDNOPART"
37
   fi
38
   echo "nameinzpool:$DEVBYIDNOPART"
39
   errorread=$($BINZPOOL status |grep "$DEVBYIDNOPART"|sed -e "s/\t//g" |sed -e "s/ \+/ /g" | sed -e "s/^ //g"|cut -d " " -f3)
40
   echo "errorread:$errorread"
41
   errorwrite=$($BINZPOOL status |grep "$DEVBYIDNOPART"|sed -e "s/\t//g" |sed -e "s/ \+/ /g" | sed -e "s/^ //g"|cut -d " " -f4)
42
   echo "errorwrite:$errorwrite"
43
   errorchecksum=$($BINZPOOL status |grep "$DEVBYIDNOPART"|sed -e "s/\t//g" |sed -e "s/ \+/ /g" | sed -e "s/^ //g"|cut -d " " -f5)
44
   echo "errorchecksum:$errorchecksum"
45
   exit 0
46
fi
47

    
48
if [[ -e /sbin/multipath ]] || [[ -e /usr/sbin/multipath ]] || [[ -e /usr/local/sbin/multipath ]]
49
then
50

    
51
    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)
52
    if [ "$resultMulti" != ""  ]
53
    then
54
        while read liner
55
        do
56
          if [[ "$liner" =~ ":" ]]
57
          then
58
              echo $liner
59
          fi 
60
        done<<< "$($SMARTTOOL -i -H /dev/disk/by-id/scsi-$resultMulti)"
61
        DEVBYIDNOPART=$(echo $DEVBYID|cut -d "/" -f4)
62
        echo "nameinzpool:$DEVBYIDNOPART"
63
        errorread=$($BINZPOOL status |grep "$DEVBYIDNOPART "|sed -e "s/\t//g" |sed -e "s/ \+/ /g" | sed -e "s/^ //g"|cut -d " " -f3)
64
        echo "errorread:$errorread"
65
        errorwrite=$($BINZPOOL status |grep "$DEVBYIDNOPART "|sed -e "s/\t//g" |sed -e "s/ \+/ /g" | sed -e "s/^ //g"|cut -d " " -f4)
66
        echo "errorwrite:$errorwrite"
67
        errorchecksum=$($BINZPOOL status |grep "$DEVBYIDNOPART "|sed -e "s/\t//g" |sed -e "s/ \+/ /g" | sed -e "s/^ //g"|cut -d " " -f5)
68
        echo "errorchecksum:$errorchecksum"
69
        exit 0
70
    fi
71
fi
72

    
73
echo "no informations disk"
74
}
75

    
76
while getopts "d:h" OPTION
77
do
78
     case $OPTION in
79
         h)
80
             usage
81
             exit 1
82
             ;;
83
         d)
84
            DEVBYID=$OPTARG
85
            ;;
86
         *)
87
           usage
88
           exit 1
89
           ;;
90
     esac
91
done
92
if [[ -z $DEVBYID ]] 
93
then
94
     usage
95
     exit 1
96
fi
97

    
98
nointeractive
99