Chinaunix首页 | 论坛 | 博客
  • 博客访问: 705057
  • 博文数量: 98
  • 博客积分: 3145
  • 博客等级: 中校
  • 技术积分: 1902
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-15 12:52
文章分类
文章存档

2021年(1)

2020年(1)

2016年(8)

2015年(3)

2014年(1)

2013年(5)

2012年(4)

2011年(9)

2010年(12)

2009年(42)

2008年(12)

我的朋友

分类: LINUX

2009-07-29 11:06:19

#! /bin/sh
WEBAPP=`netstat -nlp|grep -E "httpd|apache|lighttpd"|grep 80|awk '{print $7}'|awk -F "/" '{print $2}'`
WEBAPPPATH=`ps axww|grep "$WEBAPP"|awk '{print $5}'|head -n 1`
if [ ! -d "/home/vhost" ]
then
mkdir /home/vhost
chmod -R 755 /home/vhost
fi
IPNAME=`ifconfig |grep -E "121.194|202.205"|awk '{print $2}'|awk -F ":" '{print $2}'|head -n 1`

httpdapp(){
$WEBAPPPATH  -S >/tmp/httpdapp.txt 2>&1;
cat /tmp/httpdapp.txt |grep -i -E "port"|awk '{print $4}' >/tmp/namehost.txt
cat /tmp/httpdapp.txt |grep -i -E "port"|awk '{print $5}'|awk -F ":" '{print $1}'|awk -F "(" '{print $2}'>/tmp/hostconfig.txt
for i in `cat /tmp/hostconfig.txt`
do
cat $i|grep -E -v "#"|grep -i -E "DocumentRoot"|awk '{print $2}'|awk '{print $1}' >>/tmp/webdir.txt
cat $i|grep -E -v "#"|grep -i -E "ServerName"|awk '{print $2}'|awk '{print $1}' >>/tmp/webname.txt
done;
sed -i 's/"//g' /tmp/webdir.txt;
sed -i 's/\r//g' /tmp/webdir.txt;
sed -i 's/\r//g' /tmp/webname.txt;
paste /tmp/webdir.txt /tmp/webname.txt >/tmp/webapp.txt
for i in `cat /tmp/webdir.txt`
do
du -sh "$i" >>/tmp/websize.txt
ls -ld "$i"|awk '{print $3" "$4}' >>/tmp/webmod.txt
done
paste /tmp/webapp.txt /tmp/websize.txt >/tmp/webnew.txt
paste /tmp/webnew.txt /tmp/webmod.txt >/tmp/webnew1.txt
for j in `cat /tmp/namehost.txt`
do
cat /tmp/webnew1.txt |grep "$j"|head -n 1|awk '{print  $2"\t\t\t"$3"\t\t\t"$4"\t\t\t"$5"\t\t\t"$6}' >>/home/vhost/"$IPNAME"_vhost.txt
done;
rm /tmp/websize.txt
rm /tmp/webdir.txt
rm /tmp/webname.txt
rm /tmp/webnew.txt
rm /tmp/hostconfig.txt
rm /tmp/httpdapp.txt
rm /tmp/namehost.txt
rm /tmp/webnew1.txt
rm /tmp/webmod.txt
}
lighttpdapp(){
LIGHTTPDCONF=`ps axww|grep lighttpd|grep "lighttpd.conf"|head -n 1|awk '{print $7}'`
echo "$IPNAME" >/tmp/hostname.txt
cat $LIGHTTPDCONF |grep -E -v "#" |grep -E "HTTP"|grep -E -v "url"|awk -F "{" '{print $1}'|awk '{print $3}' >>/tmp/hostname.txt
sed -i 's/\"//g' /tmp/hostname.txt ;
cat $LIGHTTPDCONF |grep -E -v "#" |grep -E "server.document-root"|awk -F "=" '{print $2}'|awk -F "\"" '{print $2}' >/tmp/webdir.txt
for i in `cat /tmp/webdir.txt`
do
du -sh "$i" >>/tmp/websize.txt
ls -ld "$i" >>/tmp/webmod.txt
done
paste /tmp/websize /tmp/webmod.txt >/tmp/websize1.txt
paste /tmp/hostname.txt /tmp/websize1.txt >/home/vhost/"$IPNAME"_vhost.txt
rm /tmp/hostname.txt /tmp/webdir.txt /tmp/websize.txt /tmp/webmod.txt
}
if [ "$WEBAPP" = "httpd" ]
then
httpdapp;
 elif [ "$WEBAPP" = "lighttpd" ]
then
lighttpdapp;
else
echo "no webapp is find!"
fi
阅读(1289) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~