Проект

Общее

Профиль

imapsync.sh

Аноним, 20.10.2017 10:14

Загрузить (1,16 КБ)

 
1
#!/bin/bash
2

    
3
AD_USER=alp
4
AD_DOMAIN=adm72
5
PASS1=Tlhty@D0im
6

    
7
DOVECOT_USER=dovemaster
8
PASS2=Aa12345678
9

    
10
HOST1=10.142.170.5
11
HOST2=10.142.170.13
12

    
13
LOGDIR=/var/log/imapsync_batch/
14

    
15
function log {
16
	echo "[$(date)]: $*" > >(tee -a /var/log/imapsync_batch/batch.log)
17
}
18

    
19
function interrupted {
20
	log interrupted!
21
	exit 3
22
}
23

    
24
function error {
25
	log ERROR: $*
26
	exit 1
27
}
28

    
29
trap interrupted SIGINT SIGTERM
30

    
31
[ -f "$1" ] || error User list not found! Usage: $0 userlist.txt 
32

    
33
USERLIST="$1"
34
shift
35

    
36
exec 2> >(tee -a /var/log/imapsync_batch/batch.log)
37

    
38
log Starting migration of $(wc -l $USERLIST) users
39
while IFS='' read -r username || [[ -n "$username" ]]
40
do
41
	log Starting mirgation for user $username
42
	USER1="$AD_DOMAIN\\$AD_USER\\$username"
43
	USER2="$username*$DOVECOT_USER"
44
	log user1: $USER1, user2: $USER2
45
	imapsync --host1 $HOST1 --user1 "$USER1" --password1 "$PASS1" --host2 $HOST2 --user2 "$USER2" --password2 "$PASS2" --tls1 --tls2 --automap --pidfilelocking --skipemptyfolders --logdir $LOGDIR $*
46
	exit_code=$?
47
	if [[ $exit_code -ne 0 ]] ; then
48
		log Migration for user $username failed! See log in $LOGDIR
49
	else
50
		log Migration completed successfully for user $username
51
	fi
52
	
53
done < $USERLIST
54

    
55
log Done
Добавить изображение из буфера обмена (Максимальный размер: 24,4 МБ)