-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathstatistics_all_disk_files_2.sh
84 lines (77 loc) · 4.05 KB
/
statistics_all_disk_files_2.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
#!/bin/bash
# +------------------------------------------------------------------------+
# | Quanwen Zhao |
# | [email protected] |
# | quanwenzhao.wordpress.com |
# |------------------------------------------------------------------------|
# | Copyright (c) 2016-2018 Quanwen Zhao. All rights reserved. |
# |------------------------------------------------------------------------|
# | DATABASE : Oracle |
# | |
# | FILE : statistics_all_disk_files_2.sh |
# | |
# | CLASS : LINUX Bourne-Again Shell Scripts |
# | |
# | PURPOSE : This bash script file used to list the first and last file|
# | with only reserving the format of date and count total |
# | files number on each disk on Linux Server. |
# | |
# | PARAMETERS : None. |
# | |
# | MODIFIED : 29/06/2018 (dd/mm/yyyy) |
# | |
# | NOTE : As with any code, ensure to test this script in a |
# | development environment before attempting to run it in |
# | production. |
# +------------------------------------------------------------------------+
# +------------------------------------------------------------------------+
# | GLOBAL VARIABLES ABOUT THE ABSOLUTE PATH OF THE SHELL COMMAND |
# +------------------------------------------------------------------------+
export AWK=`which awk`
export CUT=`which cut`
export DU=`which du`
export ECHO=`which echo`
export GREP=`which grep`
export LS=`which ls`
export UNIQ=`which uniq`
export WC=`which wc`
# +------------------------------------------------------------------------+
# | GLOBAL VARIABLES ABOUT STRINGS AND ABSOLUTE PATH OF THE SHELL COMMAND |
# +------------------------------------------------------------------------+
export DISK_ARRAY='HDB HDC HDD HDE HDF HDG HDH HDI HDJ HDK HDL HDM HDN HDO'
export OUTPUT_FILE='/home/oracle/statistics_all_disk_files_2.txt'
# +------------------------------------------------------------------------+
# | USING THE "FOR DO ... DONE" TO ACCOMPLISH THAT PURPOSE PREVIOUS |
# +------------------------------------------------------------------------+
for i in $DISK_ARRAY
do
cd /$i;
if [ `$LS -A | $WC -w` = 0 ]; then
$ECHO -e "+---------+" >> $OUTPUT_FILE;
$ECHO -e "| *"$i"* |" >> $OUTPUT_FILE;
$ECHO -e "+---------+" >> $OUTPUT_FILE;
$ECHO -e "\r" >> $OUTPUT_FILE;
$ECHO "Total Nums: 0" >> $OUTPUT_FILE;
$ECHO -e "\r" >> $OUTPUT_FILE;
else
export FILE_STR=`$DU -h * | $AWK '{print $2}' | $CUT -d'_' -f5 | $GREP -v log | $GREP -v lost+found | $UNIQ`
$ECHO -e "+---------+" >> $OUTPUT_FILE;
$ECHO -e "| *"$i"* |" >> $OUTPUT_FILE;
$ECHO -e "+---------+" >> $OUTPUT_FILE;
$ECHO -e "\r" >> $OUTPUT_FILE;
export FILE_STR_FIRST=`$ECHO $FILE_STR | $AWK '{print $1}'`
export FILE_STR_LAST=`$ECHO $FILE_STR | $AWK '{print $NF}'`
export FILE_STR_NUMS=`$ECHO $FILE_STR | $AWK '{print NF}'`
#$ECHO $FILE_STR
#num=0;
#for j in $FILE_STR
#do
# $ECHO ${j:0:8} >> $OUTPUT_FILE;
# num=$(($num+1));
$ECHO $FILE_STR_FIRST" - "$FILE_STR_LAST >> $OUTPUT_FILE;
$ECHO -e "\r" >> $OUTPUT_FILE;
#done
$ECHO "Total Nums: "$FILE_STR_NUMS >> $OUTPUT_FILE;
$ECHO -e "\r" >> $OUTPUT_FILE;
fi
done