LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 682|回复: 2

如何把这些功能在shell script中实现

[复制链接]
发表于 2004-10-12 22:37:55 | 显示全部楼层 |阅读模式
我刚刚接触linux,所以对于shell可以说是一无所知,所以很抱歉要麻烦大家帮忙了。

要实现的功能是比较一个文件夹中的文件有没有变化
比如这个文件是 /root/tmp

保存现有的文件列表
ls /root/tmp >> /root/filecheck

然后在shell script中实现
ls /root/tmp >> /root/filechecktmp
diff --brief /root/filecheck /root/filechecktmp

如果屏幕有输出 "differ"  字符, (表明这两个文件不相同,也就是/root/file文件夹中的文件改变了) 就发一个e-mail到一个特定的信箱,比如: admin@hotmail.com(或者发送一个消息到另外一台linux workdtation,提醒管理员文件夹发生了改变)



再次感谢给予回复的朋友.
 楼主| 发表于 2004-10-12 22:55:35 | 显示全部楼层
刚刚找到这个script可以发送mail
echo "Content: Helo , You ! I'm wdl36 . " | mail root@localhost -s "Title: Hello !"
 楼主| 发表于 2004-10-13 13:01:58 | 显示全部楼层
搞定了,光靠查询论坛的帖子就解决了,看来以后要多看看这里的帖子了

1. filecheckpre.sh

ls /home/backup-group/file > /root/backupcheck

2. filecheck.sh

ls /home/backup-group/file > /root/backupchecktmp
if diff /root/backupcheck /root/backupchecktmp >/dev/null;
        then echo Files in /home/backup-group/file is the same as before;
        else echo "Content: Files in /home/backup-group/file has been changed. " | mail root@localhost -s "Title: Files is changed!";
        echo Files in /home/backup-gruop/file has been changed;
        fi



首先运行第一个帖子,为的是保存原有的文件列表
然后,当要查看/home/backup-group/file中的文件有没有改变的时候(文件名的改变,或者增加、减少了文件),如果有改变就发送mail到root@localhost
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表