View Single Post
  #2 (permalink)  
Old 07-17-2007, 11:40 AM
skout23 skout23 is offline
Junior Member
 
Posts: 8
Default cleaner still slow round robin delivery

Cleaned up the script, removed variables which could be determined, put in tests for empty msgids, and added some logic for cases where the current msg count is less than the agent count. Think I won't be adding any more to this.

Code:
#!/bin/bash
# 
# Not so quick RoundRobin split of a target inbox
# by Scott Stout
#
# modify all targetInbox to the inbox you want to roundrobin
# modify the agents array to your agents list

# Current target inbox
targetInbox=sales

# current agents as per the former database.
agents=( salesagent1 salesagent2 salesagent3 salesagent4 )

# Current agent count
agentCount=${#agents[@]}

# file used as temp scratch to copy/move the emails.
localfile="RobinCurrentMSg.txt"

# Get Current inbox size
CurrentMsgCount=`zmmailbox -m $targetInbox -z gf /inbox | grep messageCount | awk '{ print $2 }' |  sed s/","$//`

# divide the inbox size by the current number of sales agents to get the number of iterattions 
if [ $CurrentMsgCount -le $agentCount ]; then
  COUNTER=1

else
  COUNTER=$(( (CurrentMsgCount / agentCount) + 1 ))

fi

# set the main until loop to begin the countdown
until [ $COUNTER -le 0 ]; do

# RoundRobin itteration of the agents array
  for agent in ${agents[@]}
do

# Zero out the last Msg ID
CurrentMsgID=0

# Get current inxbox message ID
CurrentMsgID=`zmmailbox -m $targetInbox -z s -t message -l 1 "in:inbox" | grep "^1\." | awk '{ print $2 }'`
if (( ${#CurrentMsgID} > 2 )); then

# Copy Msg to local file
zmmailbox -m $targetInbox -z gm $CurrentMsgID > $localfile

# Add Msg to Current Agent
zmmailbox -m $agent -z am "/inbox" $localfile

# move Msg to Agent's Folder
zmmailbox -m $targetInbox -z mm $CurrentMsgID /$agent

# clear out the local file
cp /dev/null $localfile 
fi

# close the inner for loop
done

# decrement the counter for the main loop
echo "Loop Count: $COUNTER"
let COUNTER-=1

# close the main loop and exit
done

# print a quick summary
echo "Emails Processed: $CurrentMsgCount"
Thanks,
Scott

Last edited by skout23; 07-17-2007 at 11:52 AM..
Reply With Quote