-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinuxstoragecalc_v4-48.sh
312 lines (278 loc) · 9.55 KB
/
linuxstoragecalc_v4-48.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
#!/bin/bash
#
#Linux Storage Billing Script for total allocated space
#Version: 4.49
#Created; 5/15/2014 by Jim Bodden
#Modified; 7/06/2014 by Jim Bodden/Srinivas Nagapuri
#(Based on the script linuxstoragecalc_v2.sh developed by Matthew Millhouse)
#
# This script now creates a file with the hostname and date in /tmp
# In this output file, each value is labeled.
# Note: on servers running Oracle this information will be incorrect and thus skipped.
# Manual calculations will be necessary for those servers.
#*****************************
#Output format: values on a single line, separated by spaces. Sizes are in GB.
#Due to the way storage is computed with certain tools & OS's this sizes may differ slightly.
#*****************************
#*****************************
# Determin/set output filename
#-----------------------------
FILENAME="/tmp/StorageCalc_`/bin/hostname`_`date +%F`.csv"
echo " " |tee $FILENAME
#*****************************
# If server is virtual then ISVIRTUAL=1
#-----------------------------
VM1=$(lspci | grep VMware)
if [[ "$VM1" == *VMware* ]]
then
VIRTUSTAT="This is a virtual server running on VMware."
VM2=1
else
VIRTUSTAT="This is a standalone physical server."
VM2=0
fi
#*****************************
# Is the server connected to external SAN
#-----------------------------
SN1=$(lspci | egrep -i "fibre channel")
if [[ "$SN1" == *Fibre* ]]
then
SANSTAT="This server is connected to an external SAN."
SN2=1
else
SANSTAT="This server is NOT connected to an external SAN."
SN2=0
fi
#*****************************
# Is the server Multipathing
#-----------------------------
MP1=$(service multipathd status)
if [[ "$MP1" == *running* ]]
then
MULTISTAT="This server is using Multipathing."
MP2=1
else
MULTISTAT="This server is NOT using Multipathing."
MP2=0
fi
#*****************************
# Is the server Running Oracle
#-----------------------------
OR1=$(rpm -qa | grep oracle)
if [[ "$OR1" == *oracle* ]]
then
ORASTAT="This server is running Oracle -- COLLECT MANUALLY."
OUT2=1
else
ORASTAT="This server is NOT running Oracle."
OUT2=0
fi
#*****************************
# Format output in Bytes or GB's?
#-----------------------------
if [[ "$1" == *GB* ]]
then
OUT1="GB"
OUT2=1
else
OUT1="Bytes"
OUT2=0
fi
#*****************************
# Gather LUID information
#-----------------------------
ls -l /dev/disk/by-id | egrep '600' | awk '{print $9}' | sed 's/scsi\-3/LUID: /g' | cut -d'-' -f1 > /tmp/luid2.tmp
sort /tmp/luid2.tmp | uniq > /tmp/luid.tmp
#*****************************
# Gather UUID information
#-----------------------------
blkid | awk '{print $2}' | egrep -iv "type" | sed 's/UUID\=/UUID: /g' | sed 's/\"//g' > /tmp/blkid.tmp
#*****************************
# Calculate Total Storage
#-----------------------------
# Filter out device mapper and software RAID to eliminate duplication
if [[ "$OUT2" == 1 ]]
then
TotalStorage=`/sbin/fdisk -l 2>/dev/null | egrep -i "disk /dev" | egrep -iv "mapper" | awk '{total = total + $5} END {print total/1024/1024/1024}'`
else
TotalStorage=`/sbin/fdisk -l 2>/dev/null | egrep -i "disk /dev" | egrep -iv "mapper" | awk '{total = total + $5} END {print total}'`
fi
#*****************************
# Calculate Allocated Storage
#-----------------------------
if [[ "$OUT2" == 1 ]]
then
AllocatedStorage=`/bin/df -lP | egrep -iv '/media/nss' | awk '{total += $2} END {print total/1024/1024}'`
else
AllocatedStorage=`/bin/df -lP | egrep -iv '/media/nss' | awk '{total += $2} END {print total*1024}'`
fi
##############################
# Collect WWNs - if there is no SAN, the $wwn variables will be empty
##############################
read wwn1 wwn2 wwn3 wwn4 <<<$(/usr/bin/systool -av -c fc_transport 2>/dev/null | grep port_name | sort | uniq | awk '{print $3}' | sed s/\"//g )
#*****************************
# Display output and create /tmp/`/bin/hostname`_`date +%F` output file
#-----------------------------
echo " " |tee -a $FILENAME
echo "Hostname: `/bin/hostname`" |tee -a $FILENAME
echo $VIRTUSTAT |tee -a $FILENAME
echo $SANSTAT |tee -a $FILENAME
echo $MULTISTAT |tee -a $FILENAME
if [[ "$OR2" == 1 ]]
then
echo $ORASTAT |tee -a $FILENAME
exit
fi
echo "DATE,SERVER,ALLOCATED-STORAGE,TOTAL-STORAGE" |tee -a $FILENAME
if [[ "$OUT2" == 1 ]]
then
printf "%s,%s,%0.2f,%0.2f\n" `date +%F` `/bin/hostname` $AllocatedStorage $TotalStorage |tee -a $FILENAME
else
echo "`date +%F`,`/bin/hostname`,$AllocatedStorage,$TotalStorage" |tee -a $FILENAME
fi
echo "WWN1: $wwn1" |tee -a $FILENAME
echo "WWN2: $wwn2" |tee -a $FILENAME
echo "WWN3: $wwn3" |tee -a $FILENAME
echo "WWN4: $wwn4" |tee -a $FILENAME
cat /tmp/luid.tmp |tee -a $FILENAME
cat /tmp/blkid.tmp |tee -a $FILENAME
exit
#!/bin/bash
#
#Linux Storage Billing Script for total allocated space
#Version: 4.49
#Created; 5/15/2014 by Jim Bodden
#Modified; 7/06/2014 by Jim Bodden/Srinivas Nagapuri
#(Based on the script linuxstoragecalc_v2.sh developed by Matthew Millhouse)
#
# This script now creates a file with the hostname and date in /tmp
# In this output file, each value is labeled.
# Note: on servers running Oracle this information will be incorrect and thus skipped.
# Manual calculations will be necessary for those servers.
#*****************************
#Output format: values on a single line, separated by spaces. Sizes are in GB.
#Due to the way storage is computed with certain tools & OS's this sizes may differ slightly.
#*****************************
#*****************************
# Determin/set output filename
#-----------------------------
FILENAME="/tmp/StorageCalc_`/bin/hostname`_`date +%F`.csv"
echo " " |tee $FILENAME
#*****************************
# If server is virtual then ISVIRTUAL=1
#-----------------------------
VM1=$(lspci | grep VMware)
if [[ "$VM1" == *VMware* ]]
then
VIRTUSTAT="This is a virtual server running on VMware."
VM2=1
else
VIRTUSTAT="This is a standalone physical server."
VM2=0
fi
#*****************************
# Is the server connected to external SAN
#-----------------------------
SN1=$(lspci | egrep -i "fibre channel")
if [[ "$SN1" == *Fibre* ]]
then
SANSTAT="This server is connected to an external SAN."
SN2=1
else
SANSTAT="This server is NOT connected to an external SAN."
SN2=0
fi
#*****************************
# Is the server Multipathing
#-----------------------------
MP1=$(service multipathd status)
if [[ "$MP1" == *running* ]]
then
MULTISTAT="This server is using Multipathing."
MP2=1
else
MULTISTAT="This server is NOT using Multipathing."
MP2=0
fi
#*****************************
# Is the server Running Oracle
#-----------------------------
OR1=$(rpm -qa | grep oracle)
if [[ "$OR1" == *oracle* ]]
then
ORASTAT="This server is running Oracle -- COLLECT MANUALLY."
OUT2=1
else
ORASTAT="This server is NOT running Oracle."
OUT2=0
fi
#*****************************
# Format output in Bytes or GB's?
#-----------------------------
if [[ "$1" == *GB* ]]
then
OUT1="GB"
OUT2=1
else
OUT1="Bytes"
OUT2=0
fi
#*****************************
# Gather LUID information
#-----------------------------
ls -l /dev/disk/by-id | egrep '600' | awk '{print $9}' | sed 's/scsi\-3/LUID: /g' | cut -d'-' -f1 > /tmp/luid2.tmp
sort /tmp/luid2.tmp | uniq > /tmp/luid.tmp
#*****************************
# Gather UUID information
#-----------------------------
blkid | awk '{print $2}' | egrep -iv "type" | sed 's/UUID\=/UUID: /g' | sed 's/\"//g' > /tmp/blkid.tmp
#*****************************
# Calculate Total Storage
#-----------------------------
# Filter out device mapper and software RAID to eliminate duplication
if [[ "$OUT2" == 1 ]]
then
TotalStorage=`/sbin/fdisk -l 2>/dev/null | egrep -i "disk /dev" | egrep -iv "mapper" | awk '{total = total + $5} END {print total/1024/1024/1024}'`
else
TotalStorage=`/sbin/fdisk -l 2>/dev/null | egrep -i "disk /dev" | egrep -iv "mapper" | awk '{total = total + $5} END {print total}'`
fi
#*****************************
# Calculate Allocated Storage
#-----------------------------
if [[ "$OUT2" == 1 ]]
then
AllocatedStorage=`/bin/df -lP | egrep -iv '/media/nss' | awk '{total += $2} END {print total/1024/1024}'`
else
AllocatedStorage=`/bin/df -lP | egrep -iv '/media/nss' | awk '{total += $2} END {print total*1024}'`
fi
##############################
# Collect WWNs - if there is no SAN, the $wwn variables will be empty
##############################
read wwn1 wwn2 wwn3 wwn4 <<<$(/usr/bin/systool -av -c fc_transport 2>/dev/null | grep port_name | sort | uniq | awk '{print $3}' | sed s/\"//g )
#*****************************
# Display output and create /tmp/`/bin/hostname`_`date +%F` output file
#-----------------------------
echo " " |tee -a $FILENAME
echo "Hostname: `/bin/hostname`" |tee -a $FILENAME
echo $VIRTUSTAT |tee -a $FILENAME
echo $SANSTAT |tee -a $FILENAME
echo $MULTISTAT |tee -a $FILENAME
if [[ "$OR2" == 1 ]]
then
echo $ORASTAT |tee -a $FILENAME
exit
fi
echo "DATE,SERVER,ALLOCATED-STORAGE,TOTAL-STORAGE" |tee -a $FILENAME
if [[ "$OUT2" == 1 ]]
then
printf "%s,%s,%0.2f,%0.2f\n" `date +%F` `/bin/hostname` $AllocatedStorage $TotalStorage |tee -a $FILENAME
else
echo "`date +%F`,`/bin/hostname`,$AllocatedStorage,$TotalStorage" |tee -a $FILENAME
fi
echo "WWN1: $wwn1" |tee -a $FILENAME
echo "WWN2: $wwn2" |tee -a $FILENAME
echo "WWN3: $wwn3" |tee -a $FILENAME
echo "WWN4: $wwn4" |tee -a $FILENAME
cat /tmp/luid.tmp |tee -a $FILENAME
cat /tmp/blkid.tmp |tee -a $FILENAME
exit