Sell编程(2)扫描监控指定类型文件并报告是否增加

来源:互联网 发布:qq飞升锻体进阶数据 编辑:程序博客网 时间:2024/05/16 08:41
#!/bin/bash

ls *.[Pp][Dd][Ff] >previousFile.txt #将初始状态下, 所有pdf文件名保存到初始文件中

while [ : ];
do
sleep 15
ls *.[Pp][Dd][Ff] >currentFile.txt #将当前状态下, 所有pdf文件名保存到当前文件中
if [ `comm -13 previousFile.txt currentFile.txt` ];then
echo "The following pdf file(s) have been created in the last 15 seconds:"
comm -13 previousFile.txt currentFile.txt
elif [ `comm -23 previousFile.txt currentFile.txt` ];then
echo "The following pdf file(s) have been removed in the last 15 seconds:"
comm -23 previousFile.txt currentFile.txt
else echo "No pdf files have been created or removed in the last 15 seconds."
fi
ls *.[Pp][Dd][Ff] >previousFile.txt #用当前的文件夹去覆盖15秒之前的文件夹
done
0 0
原创粉丝点击