0

On my FTP server, I look for files delivered in the past day and remove in-place header & trailer records.

find .  -type f -name "CDC*" -ctime -1 -exec sed -i'' -e '1d' -e '$d' '{}'  \;

This works well.

I want to automate this in a script. But how can I send myself an email notification is no files are found? I am thinking of doing something like:

find .  -type f -name "CDC*" -ctime -1 -exec sed -i'' -e '1d' -e '$d' '{}'  \;
EXIT=`echo $?`
case $EXIT in
0) ...do stuff...
*) mail....exit
esac;;

There has to a better way, right?

4

1 回答 1

1

我很确定您可以使用进行搜索所需的任何命令,并将 awc -l传递到它的末尾。然后使用 if 语句检查是否为零。因此,使用上面的示例。

NUMLINES=`find .  -type f -name "CDC*" -ctime -1 -exec sed -i'' -e '1d' -e '$d' '{}'  \ | wc -l`

if [ "$NUMLINES" -eq 0 ] ; then
foo
fi

或类似的东西。不过,我没有检查该语法是否正确。但我确定你明白我的意思

于 2013-09-09T18:54:22.370 回答