Automation: how to change all users's individual signatures
Zimbra Automation
Zimbra automation using scripting.
How to change user's individual signatures based on their ldap attributes globally
Purpose
The purpose of this article is to show how to create a simple script which, can modify every user's signature globally, based on their ldap attribute values in ldap.
Resolution
To accomplish that task we will use two scripts. In the process I will explain why combining the two scripts into one will not work.
Script 1
#!/bin/bash path="/opt/zimbra/bin" for i in `/opt/zimbra/bin/zmprov -l gaa` do echo -ne "Checking account: $i \t" $path/zmprov ma $i zimbraPrefMailSignatureEnabled TRUE signature=`$path/zmprov ga $i | egrep "(^cn|^ou|^company|^street|^telephoneNumber|^mobile|^title)" | cut -d : -f 2 | sed 's/^\ //g'` $path/zmprov ma $i zimbraPrefMailSignature "$signature" echo "done!" done
- The first script does the following:
- set the default path to zmprov.
- sets the zimbraPrefMailSignatureEnabled attribute to TRUE.
- sets a variable called signature.
- assigns to this variable different attribute values, that are assign to that user in LDAP. In this example: (^cn|^ou|^company|^street|^telephoneNumber|^mobile|^title). The attributes can be changed as per the admin needs.
- the last line modifies the account, as it writes the values from LDAP to the signature of the user.
Script 2
#!/bin/bash path="/opt/zimbra/bin" for i in `/opt/zimbra/bin/zmprov -l gaa` do echo -ne "Adding SignatureID to account: $i \t" signatureid=`$path/zmprov ga $i zimbraSignatureId | sed -n '2p' | cut -d : -f 2 | sed 's/^\ //g'` $path/zmprov ma $i zimbraPrefDefaultSignatureId "$signatureid" $path/zmprov ma $i zimbraPrefForwardReplySignatureId "$signatureid" echo "done!" done
- The second script:
- assigns a value to the zimbraSignatureId attribute.
- assigns the value from zimbraSignatureId, to the zimbraPrefDefaultSignatureId attribute.
- assigns the value from zimbraSignatureId, to the zimbraPrefForwardReplySignatureId attribute.
Scroll down to the section "Why two scripts?", to find out how to run the scripts.
Where are these values in AdminUI
In the below photo we have two color rectangles, one green and one red . The first script is concerned with editing the values in the green and the second script is changing the values within the red rectangle.
It is important to know that even if we run the first script and the values for the signature are entered, the signature will not be active unless we modify the values in the red rectangle. When changing that in the WebUI is easy and intuitive. However, when dealing with the script, this might be overlooked.
Why two scripts?
There are two scripts because if we combine the two into one, the commands of the second script will not be implemented. The second script's main purpose is finding out the value of zimbraSignatureId attribute and assign it to other two attrs. However, even when changing the signature, this attribute will not be assigned a value for the signature ID. The only way to get this value is when the user logs in into his account. Then, we can take the value of this attribute and assign it to the other two attributes. Logging showing the issue:
Checking account: 9@azmo.com ++ /opt/zimbra/bin/zmprov ga 9@azmo.com ++ sed 's/^\ //g' ++ cut -d : -f 2 ++ egrep '(^cn|^ou|^company|^street|^telephoneNumber|^mobile|^title)' + signature='9 dsvsdv dvdssd dfvsdvs svadsv' + /opt/zimbra/bin/zmprov ma 9@azmo.com zimbraPrefMailSignatureEnabled TRUE zimbraPrefMailSignature '9 dsvsdv dvdssd dfvsdvs svadsv' ++ /opt/zimbra/bin/zmprov ga 9@azmo.com zimbraSignatureId ++ sed 's/^\ //g' ++ cut -d : -f 2 ++ sed -n 2p + signatureid=5fd31077-c448-4a97-8d7e-b1a8aa8c6930 + /opt/zimbra/bin/zmprov ma 9@azmo.com zimbraPrefDefaultSignatureId 5fd31077-c448-4a97-8d7e-b1a8aa8c6930 + /opt/zimbra/bin/zmprov ma 9@azmo.com zimbraPrefForwardReplySignatureId 5fd31077-c448-4a97-8d7e-b1a8aa8c6930 + echo 'done!' done! + for i in '`/opt/zimbra/bin/zmprov -l gaa`' + echo -ne 'Checking account: 49@azmo.com \t' Checking account: 49@azmo.com ++ /opt/zimbra/bin/zmprov ga 49@azmo.com ++ sed 's/^\ //g' ++ egrep '(^cn|^ou|^company|^street|^telephoneNumber|^mobile|^title)' ++ cut -d : -f 2 + signature='49 sefefe efefes efefef fef' + /opt/zimbra/bin/zmprov ma 49@azmo.com zimbraPrefMailSignatureEnabled TRUE zimbraPrefMailSignature '49 sefefe efefes efefef fef' ++ /opt/zimbra/bin/zmprov ga 49@azmo.com zimbraSignatureId ++ sed 's/^\ //g' ++ cut -d : -f 2 ++ sed -n 2p + signatureid= + /opt/zimbra/bin/zmprov ma 49@azmo.com zimbraPrefDefaultSignatureId '' + /opt/zimbra/bin/zmprov ma 49@azmo.com zimbraPrefForwardReplySignatureId '' + echo 'done!' done!
The + signatureid= output is only visible for the first user, because user 9@azmo.com logged in, after issuing the first script. For the second user, this is not set, and thus the next two attributes get a value of null, thus putting this commands in one script will not do all the job.
What can we do?
After running the first script, sending a global mail for the users to reload or logout/login. Then running the second script, or they might as well change this setting (in the red rectangle) themselves.
A bug is open for that here: https://bugzilla.zimbra.com/show_bug.cgi?id=101434