Friday, June 05, 2009

Script to automate Oracle Calendar Server exports

Thanks to Marco Siefert, KUTTIG GmbH, Germany for this script that he's just used on a migration from OCS to Exchange right now. It would work just as well of course for exporting in an Oracle Calendar to Zimbra migration.

No matter what I do in blogger, the indentations get screwy so I'm also putting this in the next round of migration documentation.

#!/bin/sh

export CAL_HOME=/opt/oracle/OraOcs10gHome/ocal/bin
#Set allowpasswordoption = TRUE in [UTL] section of unison.ini of OCS calendar

$CAL_HOME/uniuser -ls -format "%s%:%g%:%uid%:%id%:%node-id%:" -n 1 -p sysoppassword > users.txt
$CAL_HOME/uniuser -resource -ls "S=*" -n 1 -p sysoppassword> resources.txt
while read mylinedo
#Replacing spaces with % so it can be passed to awk

str=$myline

str=${str/\ /%}
#Declaring variables

surname=""

givenname=""

uid=""

startch=":"

endch=":"
#Launching export command with awk

echo sysoppassword awk -v str=$str -v st=$startch -v end=$endch 'BEGIN{

if (length(str)>0){

system("echo Processing line "str)
#Cutting variables out of the line

s=index(str,startch)

e=index(str,end)

givenname=substr(str,s,e-1)

surname=substr(str,e+1)

uid=surname

surname=substr(surname,0,index(surname,":")-1)

uid=substr(uid,index(uid,":")+1)

uid=substr(uid,0,index(uid,":")-1)

#Replacing % in uid for unicpoutu tool, not replacing it in givenname because that is used in the export filename

gsub("%"," ",uid)

system("echo UID="uid)

#When we have a givenname then start with export

if (length(givenname) > 0)

system("$CAL_HOME/unicpoutu -u \"UID="uid"\" -f exp-"surname"-"givenname".txt -n 1")

}

else system("echo ---------------------------------------")

}'

done <>


Reference our earlier posts on exporting data from Oracle Calendar. For example, How to Extract Data from Oracle Calendar Server for a migration into Exchange or Zimbra.

In the script the value for CAL_HOME and sysoppassword have to be replaced before running.

To provide a password to unicpoutu change the config file "unison.ini" before exporting (can be found in $CAL_HOME\ocal\misc). The line allpasswordoption = TRUE should be added to the [UTL] section.

0 comments: