sync_loop_darwin.sh 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/sh
  2. #
  3. # $Id: sync_loop_darwin.sh,v 1.3 2022/01/10 08:03:46 gilles Exp gilles $
  4. # Example for imapsync massive migration on Unix systems.
  5. # See also http://imapsync.lamiral.info/FAQ.d/FAQ.Massive.txt
  6. #
  7. # Data is supposed to be in file.txt in the following format:
  8. # host001_1;user001_1;password001_1;host001_2;user001_2;password001_2;;
  9. # ...
  10. # The separator is the character semi-colon ";"
  11. # this separator character can be changed to any character
  12. # by changing IFS=';' in the while loop below.
  13. #
  14. # Each line contains 7 columns. These columns are the 6 parameter values
  15. # for the imapsync command options
  16. # --host1 --user1 --password1 --host2 --user2 --password2
  17. # plus an extra column for extra parameters and a trailing fake column
  18. # to avoid CR LF part going in the 7th parameter extra.
  19. # So don't forget the last semicolon, especially on MacOS systems.
  20. #
  21. # You can also add extra options in this script after the variable "$@"
  22. # Those options will be applied in every imapsync run, for every line.
  23. # The imapsync command below is written in two lines to avoid a long line.
  24. # The character backslash \ at the end of the first line is means
  25. # "the command continues on the next line".
  26. #
  27. # Use character backslash \ at the end of each supplementary line,
  28. # except for the last line.
  29. #
  30. # You can also pass extra options via the parameters of this script since
  31. # they will be in "$@". Shell knowledge is your friend.
  32. # The credentials filename "file.txt" used for the loop can be renamed
  33. # by changing "file.txt" below.
  34. # The file file_failures.txt will contain the lines from file.txt that ended
  35. # up in error, for whatever reason. It's there to notice and replay easily
  36. # the failed imapsync runs. Is is emptied at the beginning of the loop run.
  37. # I let you junggle with it.
  38. echo Looping on accounts credentials found in file.txt
  39. echo
  40. line_counter=0
  41. # Empty the error listing
  42. > file_failures.txt
  43. { while IFS=';' read h1 u1 p1 h2 u2 p2 extra fake
  44. do
  45. line_counter=`expr 1 + $line_counter`
  46. { echo "$h1" | tr -d '\r' | egrep '^#|^ *$' ; } > /dev/null && continue # this skip commented lines in file.txt
  47. echo "==== Starting imapsync with --host1 $h1 --user1 $u1 --host2 $h2 --user2 $u2 $extra $@ ===="
  48. if ../imapsync_bin_Darwin --host1 "$h1" --user1 "$u1" --password1 "$p1" \
  49. --host2 "$h2" --user2 "$u2" --password2 "$p2" $extra "$@"
  50. then
  51. echo "success sync for line $line_counter "
  52. else
  53. echo "$h1;$u1;$p1;$h2;$u2;$p2;$extra;" | tee -a file_failures.txt
  54. fi
  55. echo "==== Ended imapsync with --host1 $h1 --user1 $u1 --host2 $h2 --user2 $u2 $extra $@ ===="
  56. echo
  57. done
  58. } < file.txt