-
Notifications
You must be signed in to change notification settings - Fork 0
/
disk_cleaner.sh
264 lines (164 loc) · 5.55 KB
/
disk_cleaner.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
#!/bin/bash
######################################################################
#Script Name : Disk_Cleaner Version 1.0
#Description : Its Main Stream Project To Handle Space Issues
#Author : Alvin Lazar C
#Email : alvin.la@endurance.com(alvinlaz96@yahoo.com)
######################################################################
clear;
#--Activate output via email by setting "sendmail" to 1 and uncomment "email"--#
sendmail=0
#email=user@yourdomain.com
progress()
{
pid=$! # Process Id of the previous running command
spin='-\|/'
i=0
while kill -0 $pid 2>/dev/null
do
i=$(( (i+1) %4 ))
printf "\r ${spin:$i:1}"
sleep .1
done
}
output=/tmp/wp_outdated.txt
tempf1=/tmp/search_wp
tempf2=/tmp/temp_output
conf=/usr/local/apache/conf/httpd.conf
rm -f $output
rm -f $tempf1
rm -f $tempf2
read -e -p "Enter the directory path to scan (Eg: /home, /home/*/public_html): " dir
wp_latest=$( curl -k -s "https://api.wordpress.org/core/version-check/1.6/" | awk -F'"' {'print $10'} | cut -d"-" -f2 | cut -c -5 )
echo "WordPress latest Version is $wp_latest"
find $dir -type f -iwholename "*/wp-includes/version.php" -exec grep -H "\$wp_version =" {} >> $tempf1 \; &
echo "Search in progress, this may take several minutes"
progress
echo ""
echo "Website URL | Username | Full Path | Version" >> $tempf2
echo "----------------- | -------- | --------- | -------" >> $tempf2
for j in $( sed 's/ //g' $tempf1 )
do
path=$( echo "$j" | awk -F"wp-includes" {'print $1'} | sed 's/.$//' )
nf=$( echo $path | grep -o "/" | wc -l )
ver=$( echo "$j" | cut -d\' -f2 )
user=$( echo "$path" | cut -d"/" -f3 )
lastf=""
if [ "$(printf "$wp_latest\n$ver" | sort -V | head -n1)" == "$ver" ] && [ "$ver" != "$wp_latest" ] ; then
ct=0
path_org=$path
while [ $nf -gt 2 ] ;do
if grep -q -B2 $path $conf ;then
dom=$( grep -B2 $path $conf | head -n1 | awk {'print $2'} )
echo "$dom$lastf | $user | $path_org | $ver" >> $tempf2
break
else
(( ct++ ))
lastf=/$( echo "$path_org" | rev | cut -d"/" -f1-$ct | rev )
path=$( echo "$path" | rev | cut -d"/" -f2- | rev )
(( nf-- ))
fi
done
else
sleep 1
fi
done
echo ""
if sed '3q;d' $tempf2 | grep -E -q "*" ; then
cat $tempf2 | column -s '|' -o '|' -t > $output
echo "Search completed. Find the Output file at: $output "
#Send output via email
if [ $sendmail -eq 1 ];then
echo "Please find the attachement" | mail -s "WordPress Outdated installations" -a $output $email
echo "Output has been sent to $email"
else
sleep 1
fi
else
echo "No outdated Wordpress installation found"
fi
##########
unset h,v,t,x,e,w,homr,homrx,varr,tmpr,varrx,hn,k;
#Function dsh print dashes.
dsh () {
echo -e "\n##########################################\n";
};
waiter () {
p=0;
start=$(date +%s.%N);
while [[ $(pgrep -f xargs | wc -c) -ne 0 ]];
do
printf "." sleep 1;
sleep 3;
#p=$(($p+1));
if [[ $(pgrep -f xargs | wc -c) -eq 0 ]];
then
stop=$(date +%s.%N);
dt=$(echo "$stop - $start" | bc)
dd=$(echo "$dt/86400" | bc);
dt2=$(echo "$dt-86400*$dd" | bc);
dh=$(echo "$dt2/3600" | bc);
dt3=$(echo "$dt2-3600*$dh" | bc);
dm=$(echo "$dt3/60" | bc);
ds=$(echo "$dt3-60*$dm" | bc);
echo -e "[OK]\t";
echo -ne "Execution time: %02d:%02.4f\n" $dm $ds
((totalduration+=dur))
#unset p,pi;
fi;
done
};
homr () {
if [ "$hn" == NULL ];
then
echo -e "\nOuch.. You Missed Home_Number. Running Normal Mode "; sleep 2s; clear;
((ls -A /var/cpanel/users |xargs -n1 -I{} sudo du -sh /home/{}/public_html/error_log &>/dev/null) & ) &>/dev/null;
pi=`pgrep -f xargs`;
echo -en "\n\nAll_Homes\tReport `hostname`\t`date +%d-%m-%Y`\n\n\nClearing Error Logs " ;
waiter $pi
fi; } #Remove Test Line
elif [ "$dir" == "v" ];
then
echo -e "\nVAR\n";
i=1;
else
echo -e "\n\e[1;41m \e[0m\n\tGood Bye...";
i=1;
fi;
};
homrx () { }
varr () { }
tmpr () { }
varrx () { }
clear &&
read -rep $'Enter the Disk Partion To scan (Eg: /home, /var, /tmp, /)\n\nAvailable Options (h,v,t,x) Extended Option for home(e) var(w):' dir
if [ "$dir" == "h" ];
then
hn=NULL
echo -e "\nEnter Home Number (A for All) : ";
read -r hn;
homr $hn
elif [ "$dir" == "v" ];
then
echo -e "\nDetailed Report Stored In /ramdisk/mreports.txt\n";
i=1;
elif [ "$dir" == "t" ];
then
read -rep $'\nEnter required mail:' mid;
echo -e "\n`sleep 2s`Email Successfully Sent to `cat /ramdisk/mreports.txt |mail -s "Malware Report" $mid >/dev/null`$mid\n";
i=1;
elif [ "$dir" == "x" ];
then
echo -e "\n\e[1;42m \e[0m\n";
i=1;
elif [ "$dir" == "x" ];
then
echo -e "\n\e[1;42m \e[0m\n";
i=1;
else
echo -e "\n\e[1;41m \e[0m\n\tGood Bye...";
i=1;
fi;
#echo -e "\n\e[1;33m`k=$(((RANDOM%50)));curl -sk https://raw.githubusercontent.com/alvinlaz96/SysAdmin-Scripts-Linux/master/quotes 2>/dev/null |head -$k|tail -1`\e[0m\n"
echo -e "\n\e[1;33m`k=$(((RANDOM%50)));curl -sk http://hgfix.net/paste/view/raw/92cfa34e 2>/dev/null |head -$k|tail -1`\e[0m\n"
exit 0