你可以帮我构建一个unix脚本来检查今天创建的同一位置的多个文件,我试过下面的代码,但这是检查单个文件的多个位置。
enter function WRITE_LOG(){
echo "$(date) : $@" >> ${LOG_FILE}
}
function CHECK_FILE(){
cd ${1}
WRITE_LOG "Checking files in ${1}"
ls -l | grep -q "$(date "+%Y-%m-%d").*RIG*"
if [ "$?" -eq "0" ]
then
WRITE_LOG "File created for today"
else
WRITE_LOG "File not created. please check"
fi
}
WRITE_LOG "Look for abc files" > $LOG_FILE
CHECK_FILE "/abc/zyx"
CHECK_FILE "/abc/QLD1"
CHECK_FILE "/abc/SAa"
export MAILTO="abc@xyz.com"
export CONTENT="/home/abc/LOG/HC.log"
export SUBJECT="check for files Generated Today"
(
echo "Subject: $SUBJECT"
echo "MIME-Version: 1.0"
echo "Content-Type: text/html"
echo "Content-Disposition: inline"
echo '<HTML><BODY><PRE>'
cat $CONTENT
echo '</PRE></BODY></HTML>'
) | /usr/sbin/sendmail $MAILTO
code here
答案 0 :(得分:0)
function CHECK_FILE(){
cd ${1}
WRITE_LOG "Checking files in ${1}"
FILE=`find . -type f -name "abc.RIG"`
for OUTPUT in $FILE
do
ls -l $OUTPUT | grep -q "$(date "+%Y-%m-%d").*RIG*"
if [ "$?" -eq "0" ]
then
WRITE_LOG "File created for today"
else
WRITE_LOG "File not created. please check"
fi
done
}