免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1882 | 回复: 6
打印 上一主题 下一主题

请教一个shell的编写。。。。。 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-10-14 10:41 |只看该作者 |倒序浏览
10可用积分
一个web目录 /webhome/ 里面很多文件 如x.php xx.php

我想监控 当有 新文件.php写入到webhome里就输出log。

shell要怎么写?感谢

论坛徽章:
0
2 [报告]
发表于 2008-10-14 10:56 |只看该作者
1. find -newer
2.du 来监控目录大小

论坛徽章:
0
3 [报告]
发表于 2008-10-14 11:57 |只看该作者
把*号下面代码加入 crontab每隔一定时间执行一次。
或者在外层加个循环
while 1>0
do
sleep 5
x.sh
done

***************************************************



[ -e count ] || touch count
[ -z $(cat count) ] && echo "0">count
for x in $(ls *.php)
do
i=$(($i+1))
done

j=$(cat count)

num=$(($i-$j))
echo $num" file was added"
ls -c *.php|head -n$num >> log
echo $i>count

[ 本帖最后由 jackymail 于 2008-10-14 12:04 编辑 ]

论坛徽章:
0
4 [报告]
发表于 2008-10-15 16:43 |只看该作者
#!/bin/bash
source_dir=/home/web
txt_dir=/tmp/log/
your_date=`date +%Y-%m-%d `
echo $your_date >>$txt_dir/newweb.log
find $source_dir -mtime -1 >>$txt_dir/newweb.log


放到cron里,每天执行一次

[ 本帖最后由 smz0102 于 2008-10-16 10:27 编辑 ]

论坛徽章:
0
5 [报告]
发表于 2008-10-15 21:23 |只看该作者
zj@zj:~/Script/cushell/08.10.15$ cat watch.sh
#!/bin/bash

f=$0
while(( 1 ))
do
  for file in $(find . -type f -newer $f)
  do
  echo $file
  file_name=$(basename $file)
#log不放到这个目录就可以了
  echo $file_name >> ../log
  f=$file_name
  done
done

有缺点的

论坛徽章:
0
6 [报告]
发表于 2008-10-16 11:26 |只看该作者

回复 #1 reject 的帖子

ls -l /webhome/ |awk '{print $9}' |grep -v "^$"  >nowfilelist.txt
comm -23 nowfilelist.txt lastfilelist.txt |wc -l |read addnum
if [ $addnum -gt 0 ]
then
echo "new file add   "`date` >>addlist.log
comm -23 nowfilelist.txt lastfilelist.txt >>addlist.log
fi
cat nowfilelist.txt>lastfilelist.txt

论坛徽章:
0
7 [报告]
发表于 2008-10-16 11:37 |只看该作者
内核有个功能很好
inotify

然后用软件监控目录,只要有改变,就会触发事件,就可以处理了(用perl写脚本就可以)

你可以google一下inotify,资料很多
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP