有一台服务器作为你们的web应用。有一个目录(/data/web/attachment)不定时地会被用户上传新的文件,但是不知道什么时候会上传。所以,需要我们每5分钟做一次检测是否有新文件生成,请写一个shell脚本去完成检测。检测完成后若是有新文件,还需要将新文件的列表输出到一个按年、月、日、时、分为名字的日志里。
请不要想的太复杂,核心命令只有一个 find /data/web/attachment -mmin -5
思路: 每5分钟检测一次,那肯定需要有一个计划任务,每5分钟去执行一次。脚本检测的时候,就是使用find命令查找5分钟内有过更新的文件,若是有更新,那这个命令会输出东西,否则是没有输出的。固,我们可以把输出结果的行数作为比较对象,看看它是否大于0. 参考脚本如下:
{{{密码回复可见}}}
请不要想的太复杂,核心命令只有一个 find /data/web/attachment -mmin -5
思路: 每5分钟检测一次,那肯定需要有一个计划任务,每5分钟去执行一次。脚本检测的时候,就是使用find命令查找5分钟内有过更新的文件,若是有更新,那这个命令会输出东西,否则是没有输出的。固,我们可以把输出结果的行数作为比较对象,看看它是否大于0. 参考脚本如下:
{{{密码回复可见}}}
0
本帖最后由 wyatt88 于 2014-9-15 11:16 编辑
#!/bin/bash
filedir=/data/web/attachment
Init() {
timestamp=`ls -lh --time=ctime --time-style=+%s | awk '{print $6}' | sort -n | tail -n 1`
if [ -f .tms ]
then
contxt=`cat .tms`
if [ -z $contxt ]
then
echo $timestamp > .tms
fi
else
echo $timestamp > .tms
fi
if [ ! -d $filedir/log ]
then
mkdir $filedir/log
fi
}
checkfile() {
fn=$1
if [ -f $filedir/$fn ]
then
fts=`ls -lh --time=ctime --time-style=+%s $filedir | grep "$fn" | awk '{print $6}'`
lfts=`cat .tms`
if [ $fts -gt $lfts ]
then
logfile=$filedir/log/`date +%Y-%m-%d_%H:%m`.log
echo $fn >> $logfile
echo $fts > .tms
fi
fi
}
while :;
do
Init
for file in `ls -lh --time=ctime --time-style=+%s $filedir | awk '{print $6,$NF}' | sort -n | awk '{print $2}'`
do
checkfile $file
done
sleep 300
done
能运行,可是老觉得哪有问题 铭哥,想法就是根据文件创建的时间戳来判断新文件,记录新文件后 将最后一个记录的文件时间戳记录到临时文件中,用于下次比较。
#!/bin/bash
filedir=/data/web/attachment
Init() {
timestamp=`ls -lh --time=ctime --time-style=+%s | awk '{print $6}' | sort -n | tail -n 1`
if [ -f .tms ]
then
contxt=`cat .tms`
if [ -z $contxt ]
then
echo $timestamp > .tms
fi
else
echo $timestamp > .tms
fi
if [ ! -d $filedir/log ]
then
mkdir $filedir/log
fi
}
checkfile() {
fn=$1
if [ -f $filedir/$fn ]
then
fts=`ls -lh --time=ctime --time-style=+%s $filedir | grep "$fn" | awk '{print $6}'`
lfts=`cat .tms`
if [ $fts -gt $lfts ]
then
logfile=$filedir/log/`date +%Y-%m-%d_%H:%m`.log
echo $fn >> $logfile
echo $fts > .tms
fi
fi
}
while :;
do
Init
for file in `ls -lh --time=ctime --time-style=+%s $filedir | awk '{print $6,$NF}' | sort -n | awk '{print $2}'`
do
checkfile $file
done
sleep 300
done
能运行,可是老觉得哪有问题 铭哥,想法就是根据文件创建的时间戳来判断新文件,记录新文件后 将最后一个记录的文件时间戳记录到临时文件中,用于下次比较。
0
#!/bin/bash
while :; do
old_file_num=`ls -t /data/web/attachment | wc -l`
sleep 300
new_file_num=`ls -t /data/web/attachment | wc -l`
if [ ${new_file_num} -gt ${old_file_num} ];then
now=`date +"%Y-%m-%d %H:%M"`
let num=${new_file_num}-${old_file_num}
ls -t /data/web/attachment | head -n${num} >> /root/log/${now}.log
fi
done
while :; do
old_file_num=`ls -t /data/web/attachment | wc -l`
sleep 300
new_file_num=`ls -t /data/web/attachment | wc -l`
if [ ${new_file_num} -gt ${old_file_num} ];then
now=`date +"%Y-%m-%d %H:%M"`
let num=${new_file_num}-${old_file_num}
ls -t /data/web/attachment | head -n${num} >> /root/log/${now}.log
fi
done
0
#!/bin/bash
# Desc: This is script to check the directory every five minutes,
# if a new file add ,then add to the log file.
# Author: Jeffery.Su
# Date: 15/9/2014
UP_PATH=/data/web/attachment
DATE=`date +%Y%m%d%H%M -d "+5 min"`
LOG=/tmp/${DATE}.log
while :;
do
ORG_FILE_NUM=`/bin/ls ${UP_path}|wc -l`
sleep 300;
CURR_FILE_NUM=`/bin/ls ${UP_path}|wc -l`
COUNT=$(($CURR_FILE_NUM-$ORG_FILE_NUM+2))
if [ $COUNT -gt 2 ];then
echo -e "$(date) find new file added\n"
/bin/ls -tlh ${UP_PATH} | sed -n "2,$COUNT"p > ${LOG}
fi
done
{:5_121:}
#!/bin/bash
# Desc: This is script to check the directory every five minutes,
# if a new file add ,then add to the log file.
# Author: Jeffery.Su
# Date: 15/9/2014
UP_PATH=/data/web/attachment
DATE=`date +%Y%m%d%H%M -d "+5 min"`
LOG=/tmp/${DATE}.log
while :;
do
ORG_FILE_NUM=`/bin/ls ${UP_path}|wc -l`
sleep 300;
CURR_FILE_NUM=`/bin/ls ${UP_path}|wc -l`
COUNT=$(($CURR_FILE_NUM-$ORG_FILE_NUM+2))
if [ $COUNT -gt 2 ];then
echo -e "$(date) find new file added\n"
/bin/ls -tlh ${UP_PATH} | sed -n "2,$COUNT"p > ${LOG}
fi
done
{:5_121:}
0
本帖最后由 齐天大圣 于 2014-9-15 16:31 编辑
- #!/bin/bash
- #Check new file in /data/web/attachment
- #Writen by lichao . V1
- d=`date +%y%m%d-%H:%M`
- find /data/web/attachment -type f -mmin -5 >$d.txt
- if [ ! -s $d.txt ];then
- rm -rf $d.txt
- fi
- crontab -e
- */5 * * * * /root/check_new_file.sh
0
本帖最后由 Louis 于 2014-9-15 17:28 编辑
#!/bin/bash
## This script is for check if new files have been added every 5 minute.
## IF yes.add the files name to a log named by like 201409151600.log
## Written by Louis at 2014/09/15 16:00
dir="/data/web/attachment"
while :; do
result=`find $dir -mmin -5|awk 'NR>1'|sed 's#^/data/web/attachment/##'|xargs`
if [ `echo $result|wc -l` -eq 1 ]; then
echo $result > /tmp/newattach/`date -d "-5 minute" +%Y%m%d%H%M`.log
fi
sleep 300
done
思路:利用find命令参数-mmin -5(5分钟之内)去查找文件,对查找结果处理:排除目录本身,去除结果前面的/data/web/attachment,只保留文件名,利用xargs单行显示;如处理后结果为1行,则输出到日志。
#!/bin/bash
## This script is for check if new files have been added every 5 minute.
## IF yes.add the files name to a log named by like 201409151600.log
## Written by Louis at 2014/09/15 16:00
dir="/data/web/attachment"
while :; do
result=`find $dir -mmin -5|awk 'NR>1'|sed 's#^/data/web/attachment/##'|xargs`
if [ `echo $result|wc -l` -eq 1 ]; then
echo $result > /tmp/newattach/`date -d "-5 minute" +%Y%m%d%H%M`.log
fi
sleep 300
done
思路:利用find命令参数-mmin -5(5分钟之内)去查找文件,对查找结果处理:排除目录本身,去除结果前面的/data/web/attachment,只保留文件名,利用xargs单行显示;如处理后结果为1行,则输出到日志。
0
你把文件变为一行,如果5分钟内文件很多超多1行呢?判断哪里是不是应该 [ -nq 0 ]
Louis 发表于 2014-9-15 16:31
#!/bin/bash
## This script is for check if new files have been added every 5 minute.
## IF yes.add ...
你把文件变为一行,如果5分钟内文件很多超多1行呢?判断哪里是不是应该 [ -nq 0 ]
0
本帖最后由 soar 于 2014-9-15 16:48 编辑
file=`find /data/web/attachment -mmin -5`
if [ -n "$file" ]
then
d=`date +%F-%H:%M`
echo "$file" > tmp/$d.log
fi
file=`find /data/web/attachment -mmin -5`
if [ -n "$file" ]
then
d=`date +%F-%H:%M`
echo "$file" > tmp/$d.log
fi
0
谢谢提醒。
经再次验证,使用了echo $result|wc -l,即使变量内容为空时,也为1。所以,我的脚本判断条件不对,当没有新文件,也记录空白日志了。
更正为,输出结果用xargs,判断行不用xargs、echo,判断条件用[ -ne 0 ]:
#!/bin/bash
dir="/data/web/attachment"
while :; do
line=`find $dir -mmin -5|awk 'NR>1'|sed 's#^/data/web/attachment/##'|wc -l`
result=`find $dir -mmin -5|awk 'NR>1'|sed 's#^/data/web/attachment/##'|xargs`
if [ $line -ne 0 ]; then
echo $result > /tmp/newattach/`date -d "-5 minute" +%Y%m%d%H%M`.log
fi
sleep 300
done
齐天大圣 发表于 2014-9-15 16:35
你把文件变为一行,如果5分钟内文件很多超多1行呢?判断哪里是不是应该 [ -nq 0 ]
谢谢提醒。
经再次验证,使用了echo $result|wc -l,即使变量内容为空时,也为1。所以,我的脚本判断条件不对,当没有新文件,也记录空白日志了。
更正为,输出结果用xargs,判断行不用xargs、echo,判断条件用[ -ne 0 ]:
#!/bin/bash
dir="/data/web/attachment"
while :; do
line=`find $dir -mmin -5|awk 'NR>1'|sed 's#^/data/web/attachment/##'|wc -l`
result=`find $dir -mmin -5|awk 'NR>1'|sed 's#^/data/web/attachment/##'|xargs`
if [ $line -ne 0 ]; then
echo $result > /tmp/newattach/`date -d "-5 minute" +%Y%m%d%H%M`.log
fi
sleep 300
done
0
{:4_107:}学习了,if [ -n "$file" ],-n 字符串不为"null",其中变量需用双引号引起。
soar 发表于 2014-9-15 16:46
file=`find /data/web/attachment -mmin -5`
if [ -n "$file" ]
then
{:4_107:}学习了,if [ -n "$file" ],-n 字符串不为"null",其中变量需用双引号引起。
0
方法好特别{:4_91:}
ocean 发表于 2014-9-15 11:42
#!/bin/bash
# Desc: This is script to check the directory every five minutes,
# if a new file a ...
方法好特别{:4_91:}
0
没看懂+2的含义。。{:4_118:}
ocean 发表于 2014-9-15 11:42
#!/bin/bash
# Desc: This is script to check the directory every five minutes,
# if a new file a ...
没看懂+2的含义。。{:4_118:}
0
不用xargs不是一样吗,用了感觉没什么作用啊这里,求指教{:4_107:}
Louis 发表于 2014-9-15 17:27
谢谢提醒。
经再次验证,使用了echo $result|wc -l,即使变量内容为空时,也为1。所以,我的脚本判断条 ...
不用xargs不是一样吗,用了感觉没什么作用啊这里,求指教{:4_107:}
0
觉得这个是最简单易懂的
soar 发表于 2014-9-15 16:46
file=`find /data/web/attachment -mmin -5`
if [ -n "$file" ]
then
觉得这个是最简单易懂的
0
[root@www ~]# ll -h
total 272M
-rw-r--r-- 1 root root 119K Sep 9 12:48 1.log
-rw-r--r-- 1 root root 217 Sep 12 19:03 201409121909.log
sed 从第二行开始打印 但是有可能上传一个文件 2 > 1 +2 就没事了 无论是一个 两个 还是三个新增文件
泡沫。 发表于 2014-9-15 23:03
没看懂+2的含义。。
[root@www ~]# ll -h
total 272M
-rw-r--r-- 1 root root 119K Sep 9 12:48 1.log
-rw-r--r-- 1 root root 217 Sep 12 19:03 201409121909.log
sed 从第二行开始打印 但是有可能上传一个文件 2 > 1 +2 就没事了 无论是一个 两个 还是三个新增文件
0
xargs在这里的作用,是对结果处理成一行。
详见论坛:http://www.aminglinux.com/bbs/thread-266-1-1.html
泡沫。 发表于 2014-9-15 23:27
不用xargs不是一样吗,用了感觉没什么作用啊这里,求指教
xargs在这里的作用,是对结果处理成一行。
详见论坛:http://www.aminglinux.com/bbs/thread-266-1-1.html
0
把之前写的脚本贴出来,虽然比较稚嫩,呵呵,顺便看看老师的答案
[root@myCentOS check_newfile]# cat main.sh
#!/bin/bash
while [ 1 ]
do
bash /usr/local/sbin/check_newfile/check.sh
sleep 300
done
[root@myCentOS check_newfile]# cat check.sh
#!/bin/bash
filename="/var/log/"`date +%F-%T`
touch $filename
local_path=`pwd`
if [ $local_path != '/usr/local/sbin/check_newfile' ]; then
echo "Please change the working directory to /usr/local/sbin/check_newfile"
exit
fi
if [ ! -e ./latest_files ]; then
touch latest_files
fi
ls -l /data/web/attachment| grep -v '^total' | awk '{print $NF}' > ./now_files
for file in `cat ./now_files`
do
if ! [ `grep $file ./latest_files` ]; then
echo $file >> $filename
fi
done
ls -l /data/web/attachment| grep -v '^total' | awk '{print $NF}' > ./latest_files
这里用了两层,一个是main.sh用来控制5分钟执行一次的,还有个check.sh用来比较文件新旧列表的
[root@myCentOS check_newfile]# cat main.sh
#!/bin/bash
while [ 1 ]
do
bash /usr/local/sbin/check_newfile/check.sh
sleep 300
done
[root@myCentOS check_newfile]# cat check.sh
#!/bin/bash
filename="/var/log/"`date +%F-%T`
touch $filename
local_path=`pwd`
if [ $local_path != '/usr/local/sbin/check_newfile' ]; then
echo "Please change the working directory to /usr/local/sbin/check_newfile"
exit
fi
if [ ! -e ./latest_files ]; then
touch latest_files
fi
ls -l /data/web/attachment| grep -v '^total' | awk '{print $NF}' > ./now_files
for file in `cat ./now_files`
do
if ! [ `grep $file ./latest_files` ]; then
echo $file >> $filename
fi
done
ls -l /data/web/attachment| grep -v '^total' | awk '{print $NF}' > ./latest_files
这里用了两层,一个是main.sh用来控制5分钟执行一次的,还有个check.sh用来比较文件新旧列表的
0
#!/bin/bash
path1="/data/web/attachment"
time=`date +%F-%T`
while :
do
find $path1 -mmin -5 | tee ${time}.txt
find $path1 -name *.txt -size 0 | rm -rf
sleep 300
done
或者是
while :
do
num=`find $path1 -mmin -5 | wc -l`
if [ $num -ne 0 ]
then
find $path1 -mmin -5 > ${time}.txt
fi
sleep 300
done
path1="/data/web/attachment"
time=`date +%F-%T`
while :
do
find $path1 -mmin -5 | tee ${time}.txt
find $path1 -name *.txt -size 0 | rm -rf
sleep 300
done
或者是
while :
do
num=`find $path1 -mmin -5 | wc -l`
if [ $num -ne 0 ]
then
find $path1 -mmin -5 > ${time}.txt
fi
sleep 300
done
0
#! /bin/bash
n=`find /data/web/attachment -mmin -5 `
date=`date +%F-%H:%M`
if [ ! -z $n ];then
echo "$n" >> /tmp/$date.log
fi
crontab -e
*/5 * * * * /bin/bash /usr/local/sbin/9.sh
n=`find /data/web/attachment -mmin -5 `
date=`date +%F-%H:%M`
if [ ! -z $n ];then
echo "$n" >> /tmp/$date.log
fi
crontab -e
*/5 * * * * /bin/bash /usr/local/sbin/9.sh
0
本帖最后由 jaws1689 于 2014-9-20 16:52 编辑
#! /bin/bash
#check new file
while :
do
a=`date -d "-5 min" +%Y%m%d%H%M`
b=`find /data/web/attachment/ -type f -mmin -5 | xargs ls -lrt | awk '{print $9}'`
for i in $b
do
echo "$i" >> $a.log
done
sleep 300
done
#! /bin/bash
#check new file
while :
do
a=`date -d "-5 min" +%Y%m%d%H%M`
b=`find /data/web/attachment/ -type f -mmin -5 | xargs ls -lrt | awk '{print $9}'`
for i in $b
do
echo "$i" >> $a.log
done
sleep 300
done
0
#!/bin/bash
while :;do
n=`find /data/web/attachment -mmin -5 -type f`
if [ ! -z $n ];then
now=`date +"%Y%m%d-%H:%M"`
echo "$n" >> /data/$now.log
fi
sleep 300
done
while :;do
n=`find /data/web/attachment -mmin -5 -type f`
if [ ! -z $n ];then
now=`date +"%Y%m%d-%H:%M"`
echo "$n" >> /data/$now.log
fi
sleep 300
done
0
- #!/bin/bash
- dir="/root/file/"
- time=`date +%F.%H:%M`
- num=`find $dir -mmin -2|wc -l`
- if [ $num -gt 1 ] ;then
- /bin/find $dir -mmin -2 |grep -v "$dir$">> /root/shell/$time.log
- fi
0
创建一个定时任务
crontab -e
*/5 * * * * sh /usr/local/sbin/09-15.sh
脚本如下:
目录是我乱编的
#!/bin/bash
find /etc/ -type f -a -mmin -5 >/tmp/15.log
n=`cat /tmp/15.log|wc -l`
date=`date '+%Y-%m-%d_%H%M'`
if [ $n -ne 0 ];then
cat /tmp/15.log >>/tmp/$date.log
rm -rf /tmp/15.log
else
rm -rf /tmp/15.log
fi
crontab -e
*/5 * * * * sh /usr/local/sbin/09-15.sh
脚本如下:
目录是我乱编的
#!/bin/bash
find /etc/ -type f -a -mmin -5 >/tmp/15.log
n=`cat /tmp/15.log|wc -l`
date=`date '+%Y-%m-%d_%H%M'`
if [ $n -ne 0 ];then
cat /tmp/15.log >>/tmp/$date.log
rm -rf /tmp/15.log
else
rm -rf /tmp/15.log
fi
0
果然不能中断啊,自己写的东西都快看不懂了
丁张龙 发表于 2014-11-23 23:33
创建一个定时任务
crontab -e
*/5 * * * * sh /usr/local/sbin/09-15.sh
果然不能中断啊,自己写的东西都快看不懂了
0
上次的忘了,又写了一个
#!/bin/bash
d=`date +%F_%H%:S`
find /home/ -mmin -5 -type f >/tmp/15.log
n=`cat /tmp/15.log|wc -l`
[ $n -gt 0 ]&&mv /tmp/15.log /tmp/new_$d.log
#!/bin/bash
d=`date +%F_%H%:S`
find /home/ -mmin -5 -type f >/tmp/15.log
n=`cat /tmp/15.log|wc -l`
[ $n -gt 0 ]&&mv /tmp/15.log /tmp/new_$d.log
0
#!/bin/bash
d=`date +%F\ %T.log`
f=`find /data/web/attachment/ -mmin -5` >dev/null
if [ -n $f ]
then
echo $f > $d
if
d=`date +%F\ %T.log`
f=`find /data/web/attachment/ -mmin -5` >dev/null
if [ -n $f ]
then
echo $f > $d
if
0
a=`find /data/web/attachment -mmin -5|wc -l`
b=`find /data/web/attachment -mmin -5`
c=`date`
if [$a -gt 0]
then
echo "$b" >>"$c".log
fi
/5 * * * * sh 1.sh
b=`find /data/web/attachment -mmin -5`
c=`date`
if [$a -gt 0]
then
echo "$b" >>"$c".log
fi
/5 * * * * sh 1.sh
0
#!/bin/bash
d=`date -d "-5 min" +%Y%m%d%H%M` ##生成一个5分钟之前的日志文件
basedir=/tmp/shell ##要检查的目录
find $basedir/ -type f -mmin -5 > /tmp/newf.txt
n=`wc -l /tmp/newf.txt`
if [ ! -z "$n" ]; then
/bin/mv /tmp/newf.txt /tmp/$d
fi
d=`date -d "-5 min" +%Y%m%d%H%M` ##生成一个5分钟之前的日志文件
basedir=/tmp/shell ##要检查的目录
find $basedir/ -type f -mmin -5 > /tmp/newf.txt
n=`wc -l /tmp/newf.txt`
if [ ! -z "$n" ]; then
/bin/mv /tmp/newf.txt /tmp/$d
fi
0
#/bin/bash while :; do sleep 300 w=`date +%Y%m%d%H%M` k=`find /root/zhai/ -mmin -5|wc -l` m=$[$k-1] if [ $m -gt 0 ]; then a=`find /root/zhai/ -mmin -5|tail -$m|sed 's#/root/zhai/##g'` for i in $a do #if [ $i -gt 0 ] ;then echo " $i" >>$w.txt #fi done fi done
0
- #!/bin/bash
- list=`find /tmp -type f -mmin -50`
- while :
- do
- if [ -n "$list" ]; then
- find /tmp -type f -mmin -50 > `date +"%Y%m%d-%H%M"`.log
- fi
- sleep 300
- done
0
- #!/bin/bash
- fdir="/data/web/attachment";
- logfile=`date +%Y%m%d%H%M`;
- filelist=`find $fdir -mmin 5`;
- m=`cat $filelist|wc -l`
- if [ $m -gt 0 ]
- then
- echo $filelist >/var/log/"$logfile".log
- fi
0
本帖最后由 syk 于 2016-1-26 16:44 编辑
#!/bin/bash
d=`date +"%Y-%m-%d-%H-%M"`
ml=`find /data/web/attachment/ -mmin -5`
for i in `ls $ml|wc -l`; do
if [ $i -gt 0 ]; then
echo "$ml" > /tmp/$d\.log
fi
done
sleep 300
铭哥指导指导
#!/bin/bash
d=`date +"%Y-%m-%d-%H-%M"`
ml=`find /data/web/attachment/ -mmin -5`
for i in `ls $ml|wc -l`; do
if [ $i -gt 0 ]; then
echo "$ml" > /tmp/$d\.log
fi
done
sleep 300
铭哥指导指导
0
#!/bin/bash
d=`date +%Y%m%d-%H%M`
f=`find /data/web/attachment -mmin -5 -type f |wc -l`
echo $f
if [ $f -ne 0 ]
then
find /data/web/attachment -mmin -5 -type f > /tmp/$d.log
fi
d=`date +%Y%m%d-%H%M`
f=`find /data/web/attachment -mmin -5 -type f |wc -l`
echo $f
if [ $f -ne 0 ]
then
find /data/web/attachment -mmin -5 -type f > /tmp/$d.log
fi
0
[ -n STRING ] or [ STRING ] “STRING” 的长度为非零 non-zero则为真。
soar 发表于 2014-9-15 16:46
file=`find /data/web/attachment -mmin -5`
if [ -n "$file" ]
then
[ -n STRING ] or [ STRING ] “STRING” 的长度为非零 non-zero则为真。
0
- #!/bin/bash
- while :;do
- DATE=`date +%F\ %T`
- n=`find /data/web/attachment -mmin -5`
- m=`find /data/web/attachment -mmin -5|wc -l`
- if [ $m -gt 0 \;then
- >/data/web/$DATE.log
- echo $n >/data/web/$DATE.log
- fi
- done
- sleep 300
0
- d=`date +%F-%H:%M`
- e=`ls /data/web/attachment | wc -l`
- f=`find /data/web/attachment -mmin -5 |wc -l`
- if [ $f -gt $e ]
- then "find /data/web/attachment -mmin -5 -exec ls -l { } ;|tee $d.log"
- else
- echo "there is not new file published"
- fi
0
- #!/bin/bash
- ##written by lin
- while :;
- do
- i=`find /data/web/attachment/ -mmin -5 |wc -l`
- if [ $i -gt 0 ]
- then find /data/web/attachment/ -mmin -5 > `date +%F-%H:%M`.log
- fi
- sleep 3000
- done
0
[root@localhost shell]# vim find5.sh
#!/bin/bash
find /tmp/ -type f -mmin -5 > /tmp/file_$(date +'%Y-%m-%d_%H:%M'.log)
#!/bin/bash
find /tmp/ -type f -mmin -5 > /tmp/file_$(date +'%Y-%m-%d_%H:%M'.log)
0
#! /bin/bash
#see if any new files are created within 5 minutes.
year=`date +%Y`
log=`find /root/shell_practice -mmin -5 |awk '{print $year"-"$6"-"$7"-"$8}'`.log
if [ `find /root/shell_practice -mmin -5 |wc -l` -gt 0 ]
then
echo "New files are created in the last 5 minutes."
touch $log
find /root/shell_practice -mmin -5 > $log
fi
#see if any new files are created within 5 minutes.
year=`date +%Y`
log=`find /root/shell_practice -mmin -5 |awk '{print $year"-"$6"-"$7"-"$8}'`.log
if [ `find /root/shell_practice -mmin -5 |wc -l` -gt 0 ]
then
echo "New files are created in the last 5 minutes."
touch $log
find /root/shell_practice -mmin -5 > $log
fi
0
while :; do
for i in ` find /data/web/attachment -mmin -5` ; do
if [ ! -z $i] ;then
echo "$i" >/tmp/`date +%F-%T`.log
fi
done
sleep 300
done
0
d=`date +"%Y-%m-%d %H:%M "`
n=`/bin/find /data/web/attachment -mmin -5`
if [ -n "$n" ]
then
/bin/find /data/web/attachment -mmin -5 >>/tmp/$d.txt
fi
计划任务:
#this cron use for checking new upload attachment
5 * * * * /bin/sh /usr/local/sbin/check_file.sh
#!/bin/bashd=`date +"%Y-%m-%d %H:%M "`
n=`/bin/find /data/web/attachment -mmin -5`
if [ -n "$n" ]
then
/bin/find /data/web/attachment -mmin -5 >>/tmp/$d.txt
fi
编辑回复