Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- index=0
- imapsync="/var/src/imapsync-1.518/imapsync"
- domain=$1
- rawlist="user.list.apppass.$1.txt"
- ips="$rawlist"
- dead="user.list.not_updated.$domain"
- if [ $# -eq 0 ];
- then
- echo "No arguments supplied. Usage ./sync_imap_multithread.sh <domain> <lines_count>"
- exit 0
- fi
- threads=$2
- split -l $threads $rawlist $domain.mpf.
- files=($domain.mpf.*)
- echo ${files[*]}
- OUTPUT="log_mt.$1"
- mkfifo $OUTPUT &> /dev/null
- sync () {
- echo "begin $1"
- while read line ; do
- if [[ $line == *"Storage"* ]]; then continue; fi
- sync_user=$(echo $line | awk -F" " '{print $1}')
- password=$(echo $line | awk -F" " '{print $2}')
- RETVAL=256
- #while [ $RETVAL -gt 1 ]; do
- echo "Syncing $sync_user"
- $imapsync --host1 frontend-1.ru --authuser1 $sync_user@$domain --user1 $sync_user@$domain --password1 $password --host2 frontend-2.ru --authuser2 $sync_user@$domain --user2 $sync_user@$domain --password2 $password | tee $sync_user_$domain.log
- sleep 3
- echo "Returning value: $RETVAL"
- if [ $RETVAL -eq 255 ]; then
- echo "$sync_user: config error. Skipped" >> $dead
- break
- fi
- if [ $RETVAL -eq 143 ]; then
- echo "$sync_user: connection error. Terminated" >> $dead
- fi
- if [ $RETVAL -eq 1 ]; then
- echo "$sync_user: finished with errors" >> $dead
- continue
- fi
- # done
- done < $1
- echo "end $1"
- }
- for x in "${files[@]}"; do
- echo "spawn $x";
- sync $x &
- done
- echo waiting
- wait
- echo done waiting
- echo Cleaning
- #cat $OUTPUT
- rm $OUTPUT
- for x in "${files[@]}"; do
- rm $x
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement