bash: tail: write error: Broken pipe

digidax

New Member
Credits
20
Hello there,

I've wroting a script "filter_postfix_SASL_fail_dmn.sh" for notifying me if a SALS login failure was found:
Bash:
#!/bin/sh
# Postfix SASL fail

tail -fn0 /var/log/maillog | while read line ; do
stamp=`grep "SASL PLAIN authentication failed" /var/log/maillog | tail -n 1 | cut -d ' ' -f 1-3`
ip=`grep "SASL PLAIN authentication failed" /var/log/maillog | tail -n 1 | cut -d '[' -f 3 | cut -d ']' -f 1`

mail -s "Postfix SASL failed" [email protected] <<< "Date: $stamp
    IP: $ip
    ";
done
For running the script I use in Centos 7.8 a systemd service called "maillogmon.service":
Code:
[Unit]
Description=Mail Log Monitor SASL fail logins
After=network.target

[Service]
Type=simple
ExecStart=/bin/bash /usr/local/bin/filter_postfix_SASL_fail_dmn.sh
TimeoutStartSec=0
Restart=always
StartLimitInterval=0

[Install]
WantedBy=default.target
in /var/log/maillog I see cyclic the lines:
Code:
Sep 16 09:00:16 farm11 bash: tail: write error: Broken pipe
Sep 16 09:00:16 farm11 bash: tail: write error
Sep 16 09:00:16 farm11 systemd: maillogmon.service holdoff time over, scheduling restart.
Sep 16 09:00:16 farm11 systemd: Stopped Mail Log Monitor SASL fail logins.
Sep 16 09:00:16 farm11 systemd: Started Mail Log Monitor SASL fail logins.
What's going wrong and how can I fix it? Basicly the script is working but the cyclic restarting of the service is unnormal I think.

Thanks, Frank
 


JasKinasis

Well-Known Member
Credits
3,079
When you're using tail -f to monitor a file - if tail attempts to read the file at the exact same time that another process is writing to the file, you'll get the "Broken pipe" error.

I think using the -F option (equivalent to -f --retry) will side-step the problem with the error message.
If the file is unavailable, tail will retry it until it can open it..... I think!
 

digidax

New Member
Credits
20
Thank for the explanation, have changed to -F but this had no effect, the problem still occurs. The -F option is in this CentOS 7.8 distri available:
Code:
tail --help
Usage: tail [OPTION]... [FILE]...
Print the last 10 lines of each FILE to standard output.
With more than one FILE, precede each with a header giving the file name.
With no FILE, or when FILE is -, read standard input.

Mandatory arguments to long options are mandatory for short options too.
  -c, --bytes=K            output the last K bytes; or use -c +K to output
                             bytes starting with the Kth of each file
  -f, --follow[={name|descriptor}]
                           output appended data as the file grows;
                             an absent option argument means 'descriptor'
  -F                       same as --follow=name --retry
 


Members online


Latest posts

Top