-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswap.sh
126 lines (103 loc) · 2.47 KB
/
swap.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
#!/bin/sh
os=`uname`
tempfile1=swap.tmp
tempfile2=swap.tmp.1
tempfile3=swap.tmp.3
rm -rf $tempfile1
rm -rf $tempfile2
temp1=0
temp2=0
total=0
free=0
used=0
util=0
if [ "$os" = "linux" ] || [ "$os" = "Linux" ]
then
swapon -s | grep /dev > $tempfile1
cat $tempfile1 | awk '{ print $3 }' > $tempfile2
for var in `cat $tempfile2`
do
total=`expr $total + $var`
done
cat $tempfile1 | awk '{ print $4 }' > $tempfile2
for var in `cat $tempfile2`
do
used=`expr $used + $var`
done
free=`expr $total - $used`
util=`expr $used \* 100 / $total`
total=`expr $total / 1024`
used=`expr $used / 1024`
free=`expr $free / 1024`
elif [ "$os" = "SunOS" ]
then
swap -l | grep /dev > $tempfile1
cat $tempfile1 | awk '{ print $4 }' > $tempfile2
for var in `cat $tempfile2`
do
total=`expr $total + $var`
done
cat $tempfile1 | awk '{ print $5 }' > $tempfile2
for var in `cat $tempfile2`
do
free=`expr $free + $var`
done
total=`expr $total / 2`
free=`expr $free / 2`
used=`expr $total - $free`
util=`expr $used \* 100 / $total`
total=`expr $total / 1024`
used=`expr $used / 1024`
free=`expr $free / 1024`
elif [ "$os" = "AIX" ] || [ "$os" = "aix" ]
then
temp1=`lsps -s | tail -1 | awk '{print $1}'`
total=`echo $temp1 | awk '{gsub("MB"," "); print $0}'`
temp2=`lsps -s | tail -1 | awk '{print $2}'`
util=`echo $temp2 | awk '{gsub("%"," "); print $0}'`
used=`lsps -s | tail -1 | awk '{print ($1 * $2 / 100)}'`
elif [ "$os" = "HP-UX" ]
then
swapinfo | grep /dev > $tempfile1
cat $tempfile1 | awk '{ print $2 }' > $tempfile2
for var in `cat $tempfile2`
do
total=`expr $total + $var`
done
cat $tempfile1 | awk '{ print $3 }' > $tempfile2
for var in `cat $tempfile2`
do
used=`expr $used + $var`
done
free=`expr $total - $used`
util=`expr $used \* 100 / $total`
total=`expr $total / 1024`
used=`expr $used / 1024`
free=`expr $free / 1024`
elif [ "$os" = "SCO_SV" ] || [ "$os" = "UnixWare" ]
then
swap -l | grep /dev > $tempfile1
cat $tempfile1 | awk '{ print $4 }' > $tempfile2
for var in `cat $tempfile2`
do
total=`expr $total + $var`
done
cat $tempfile1 | awk '{ print $5 }' > $tempfile2
for var in `cat $tempfile2`
do
free=`expr $free + $var`
done
total=`expr $total / 2`
free=`expr $free / 2`
used=`expr $total - $free`
util=`expr $used \* 100 / $total`
total=`expr $total / 1024`
used=`expr $used / 1024`
free=`expr $free / 1024`
else
echo "tobe done"
fi
echo "Total Swap=$total "
echo "Used Swap=$used"
echo "Swapspace Utilization=$util"
exit