No. The reason is that tee
doesn't work on "lines" or "words" or anything like that: it works on data streams (redirections) and what is in these streams is of no concern to tee
.
I don't know with how much data we are dealing here, so i just hope my suggestions will not be outright unfeasible. Instead of writing the list directly to the file you could write a program which checks one line after the other if it is already there and write it only if it is not. This program would get the output of your command as input. You could write to a named pipe instead of a file. To be honest i found at least two questionable points in your program:
while true; do echo $(fail2ban-client status asterisk-iptables | grep 'IP list' | sed 's/.*://g' | sed -e 's/^[ \t]*//') | tee -a ~/ips; sleep 60; done
First: the calls to sed
and grep
could be combined:
while true; do echo $(fail2ban-client status asterisk-iptables | sed -n '/IP list/ {;s/.*://g'; s/^[ \t]*//;p;}') | tee -a ~/ips; sleep 60; done
Second, what exactly do you need the tee
at all for? It makes two datastreams out of one, so that you can process it two times insteead of one (actually this is where the name comes from - the "t-piece" which plumbers use to make two hoses out of one). But you only have one data stream (which goes into the file), so you do not need another, no?
while true; do echo $(fail2ban-client status asterisk-iptables | sed -n '/IP list/ {;s/.*://g'; s/^[ \t]*//;p;}') >> ~/ips; sleep 60; done
On a further thought i do not understand what the "echo" and the subshell is for either:
while :; do fail2ban-client status asterisk-iptables | sed -n '/IP list/ {;s/.*://g'; s/^[ \t]*//;p;}' >> ~/ips; sleep 60; done
So, make ~/.ips
a named pipe, and let a separate script read it and put the result into a final file, something like this (its input will come from ~/.ips
):
#! /bin/ksh
typeset finalfile="/some/where/final"
exec 3>>"$finalfile"
while read line ; do
if grep -qv "$line" "$finalfile" ; then
print -u3 - "$line"
fi
done
exec 3>&-
exit 0
Again, if this is feasible depends on how big the file is and how many entries per minute arrive. If the numbers are small enough this will work.
I hope this helps.
bakunin