使用 POSIX 扩展正则表达式匹配 .file

使用 POSIX 扩展正则表达式匹配 .file

我尝试使用 POSIX 扩展正则表达式匹配任何前面带有点的文件。我知道在正则表达式中这是^\..*

这就是我的用法:

#!/bin/sh
MONITORDIR1="/hdd_1/path/to/dir"
MONITORDIR2="/hdd_1/path/to/dir"
#MONITORDIR3="/hdd_1/path/to/dir"
#MONITORDIR4="/hdd_1/path/to/dir"

monitor() {
inotifywait -m -r -e create --format "%f" "$1" | while read NEWFILE
do
echo "This is an automated email." | mail -s "${NEWFILE} has been added to Daemon!" "[email protected]"
done
}
monitor "$MONITORDIR1" &
monitor "$MONITORDIR2" &
#monitor "$MONITORDIR3" &
#monitor "$MONITORDIR4" &

答案1

#!/bin/sh
MONITORDIR1="/hdd_1/path/to/dir"
MONITORDIR2="/hdd_1/path/to/dir"
#MONITORDIR3="/hdd_1/path/to/dir"
#MONITORDIR4="/hdd_1/path/to/dir"

monitor() {
inotifywait -m -r -e create --exclude '/\..+' --format "%f" "$1" | while read NEWFILE
do
        echo "This is an automated email." | mail -s "${NEWFILE} has been added to Daemon!" "[email protected]"
done
}
monitor "$MONITORDIR1" &
monitor "$MONITORDIR2" &
#monitor "$MONITORDIR3" &
#monitor "$MONITORDIR4" &

相关内容