Initial import
This commit is contained in:
52
add_custom_log_to_vhost.sh
Executable file
52
add_custom_log_to_vhost.sh
Executable file
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
vhost_config_dir=/usr/local/apache2/conf/vhosts
|
||||
|
||||
_temp_dir=`mktemp -d`
|
||||
|
||||
cp -a $vhost_config_dir ${vhost_config_dir}-`date +%Y%m%d-%H%M`
|
||||
|
||||
files=`find $vhost_config_dir -maxdepth 1 -mindepth 1 -type f -print`
|
||||
|
||||
_tmp_file=`mktemp`
|
||||
echo false > $_tmp_file
|
||||
|
||||
find "$vhost_config_dir" -maxdepth 1 -mindepth 1 -type f -print | while read _file ; do
|
||||
echo "$_file"
|
||||
[[ "`basename $_file`" = "0000-logformat.conf" ]] && continue;
|
||||
[[ "`basename $_file`" = "000-default.conf" ]] && continue;
|
||||
new_file="$_temp_dir/`basename $_file`"
|
||||
while IFS='' read -r line || [[ -n $line ]]; do
|
||||
if [[ "$line" =~ "<VirtualHost" ]] ;then
|
||||
if [[ "$line" =~ "]:" ]]; then
|
||||
log_entry="CustomLog /var/log/apache2/ipv6_requests.log base_requests"
|
||||
else
|
||||
log_entry="CustomLog /var/log/apache2/ipv4_requests.log base_requests"
|
||||
fi
|
||||
echo "true" > $_tmp_file
|
||||
fi
|
||||
if [[ "$line" =~ "$log_entry" ]]; then
|
||||
echo "false" > $_tmp_file
|
||||
fi
|
||||
if [[ "$line" =~ "</VirtualHost" ]]; then
|
||||
if `cat $_tmp_file | head -n 1` ; then
|
||||
#echo "" >> $new_file
|
||||
## - with tabstop
|
||||
#echo -e " $log_entry" >> $new_file
|
||||
## - with blank signs
|
||||
echo -e " $log_entry" >> $new_file
|
||||
echo "" >> $new_file
|
||||
fi
|
||||
echo false > $_tmp_file
|
||||
fi
|
||||
echo "$line" >> $new_file
|
||||
done < $_file
|
||||
done
|
||||
|
||||
|
||||
find $_temp_dir -maxdepth 1 -mindepth 1 -type f -print -exec cp -f {} $vhost_config_dir/ \; > /dev/null 2>&1
|
||||
|
||||
rm -f $_tmp_file
|
||||
rm -rf $_temp_dir
|
||||
|
||||
exit
|
||||
Reference in New Issue
Block a user