Advertisement
Guest User

Untitled

a guest
Apr 20th, 2017
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. index=0
  4.  
  5. imapsync="/var/src/imapsync-1.518/imapsync"
  6.  
  7. domain=$1
  8. rawlist="user.list.apppass.$1.txt"
  9.  
  10. ips="$rawlist"
  11. dead="user.list.not_updated.$domain"
  12.  
  13. if [ $# -eq 0 ];
  14. then
  15. echo "No arguments supplied. Usage ./sync_imap_multithread.sh <domain> <lines_count>"
  16. exit 0
  17. fi
  18.  
  19. threads=$2
  20.  
  21. split -l $threads $rawlist $domain.mpf.
  22. files=($domain.mpf.*)
  23. echo ${files[*]}
  24.  
  25. OUTPUT="log_mt.$1"
  26. mkfifo $OUTPUT &> /dev/null
  27.  
  28. sync () {
  29. echo "begin $1"
  30. while read line ; do
  31. if [[ $line == *"Storage"* ]]; then continue; fi
  32. sync_user=$(echo $line | awk -F" " '{print $1}')
  33. password=$(echo $line | awk -F" " '{print $2}')
  34.  
  35. RETVAL=256
  36. #while [ $RETVAL -gt 1 ]; do
  37. echo "Syncing $sync_user"
  38. $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
  39. sleep 3
  40.  
  41. echo "Returning value: $RETVAL"
  42. if [ $RETVAL -eq 255 ]; then
  43. echo "$sync_user: config error. Skipped" >> $dead
  44. break
  45. fi
  46. if [ $RETVAL -eq 143 ]; then
  47. echo "$sync_user: connection error. Terminated" >> $dead
  48. fi
  49. if [ $RETVAL -eq 1 ]; then
  50. echo "$sync_user: finished with errors" >> $dead
  51. continue
  52. fi
  53. # done
  54. done < $1
  55. echo "end $1"
  56. }
  57.  
  58. for x in "${files[@]}"; do
  59. echo "spawn $x";
  60. sync $x &
  61. done
  62.  
  63. echo waiting
  64. wait
  65. echo done waiting
  66.  
  67. echo Cleaning
  68. #cat $OUTPUT
  69. rm $OUTPUT
  70. for x in "${files[@]}"; do
  71. rm $x
  72. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement