use incron
/var/spool/incron:
/var/vmail/22222.xemple.com/aaaa/new IN_MOVED_TO,IN_ONESHOT /sys_my/postfix-mail/checker_postfix-parser.sh
--------------------- stop read! older solution is not good ----
I use ather programs for do it https://github.com/rvoicilas/inotify-tools/wiki#info
server: centos 6
script postfix-parser.sh to test if new letter comes to folder:
#!/bin/bash
###
### sh /sys_my/postfix-mail/postfix-parser.sh
while ((i<=END)); do
EVENT=$(inotifywait --format '%e' /var/vmail/22222.xemple.com/aaaa/new)
if [ "$EVENT" == "CREATE" ]; then
echo $EVENT
let ii++
echo $ii
fi
done
script checker_postfix-parser.sh to check if script run:
#!/bin/bash
###
# sh /sys_my/postfix-mail/checker_postfix-parser.sh
result=`ps aux | grep -i "postfix-parser.sh" | grep -v "grep" | wc -l`
if [ $result -ge 1 ]
then
echo "script is running"
else
sh /sys_my/postfix-mail/postfix-parser.sh
fi
add to startup:
add this line:
sh /sys_my/postfix-mail/checker_postfix-parser.sh
to file:
/etc/rc.d/rc.local
run checker in cron every 5 min:
*/1 * * * * root sh /sys_my/postfix-mail/checker_postfix-parser.sh