Thursday, June 28, 2018

Shell script to update device user association in batch

Shell script to update device user association in batch


Referring to my previous post:
http://pandaeatsbamboo.blogspot.hk/2014/01/associate-existing-phones-to-users-with.html

I have created a shell script that allow us to update the owner ID to phone in batch.


bulk-update.sh, change with your UCM ip address and credential in the curl statement.

#!/bin/sh

for i in `less user-phone-list.txt`
        do 
                #echo $i
                username=`echo $i | cut -d , -f1`
                devicename=`echo $i | cut -d , -f2`
                 

cat <<EOF1 >$username.xml
<soapenv:Envelope >

    <soapenv:Header/>

    <soapenv:Body>

        <ns:executeSQLUpdate sequence="?">

EOF1

                echo "<sql>update Device set fkenduser = ( select pkid from EndUser where userid = $username)  where name = $devicename</sql>" >>$username.xml

cat <<EOF2 >>$username.xml
        </ns:executeSQLUpdate>

    </soapenv:Body>

</soapenv:Envelope>
EOF2

        curl -k -u administrator:ccievoice -H "Content-type: text/xml;" -H "SOAPAction: CUCM:DB ver=8.5" -d @$username.xml https://10.1.90.11:8443/axl/
        
        done


user-phone-list.txt, file contains username and device name pair with comma as delimiter, put them in the same directory as the script.

dannywon,SEPAABBAABBAABB
briacho,SEP00077DDFFB7E




go to link download

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.