This is what I've done using file descriptors to search through all archive mailboxes (I know zmmboxsearch does this but it failed MISERABLY) using zmmailbox.
...
...
QUERY="search -l 999 -t message ...."
QUERY_NEXT="search -n"
..
..
#return code
RC=0
# Use the PID ($$) in the FIFO and remove it on exit:
FIFO="/tmp/-pipe.$$"
mkfifo ${FIFO} || exit $?
# Tie FD3 to the FIFO (only for writing), then start zmmailbox in the
# background with its input from the FIFO:
exec 3<>${FIFO}
echo "sending output to temporary file ${TMP_LIST}"
zmmailbox -u
https://localhost:7071 -z <${FIFO} >> ${TMP_LIST} &
ZIMBRA_ARCHIVE=$!
echo "zmmailbox PID is" ${ZIMBRA_ARCHIVE}
#loop through all archives
for user in $(zmprov gaa | grep "com.archive")
do
THEACCOUNT=${user}
#wait till zmmailbox give us a prompt
#sleep 5
echo "opening mailbox" ${THEACCOUNT}
echo sm ${THEACCOUNT} >&3
sleep 5
echo ${QUERY} >&3
sleep 10
is_more
echo "first check says" $MORE
#the return code
RC=3
#loop through multiple pages of search output
while [ "$MORE" == "true" ]; do
echo ${QUERY_NEXT} >&3
sleep 10
is_more
echo "account" ${THEACCOUNT} "there's even more:" $MORE
done
done
...
...
is_more is a function that checks is there are more pages in the query results
is_more()
{
read MORE < <(sed -n -e '/^mbox\|num|more/p' ${TMP_LIST} | grep -v mailbox | awk '{if ( NF == 6 ) { print $6} }' | tail -1 )
}
--------------------------------------------
I had some problems with timing though - that's why the "
sleep" lines when I had to wait for the query to complete before sending "send me the next page" to FD3
Perhaps someone else can help me out
Doros