Showing posts with label Shell Script. Show all posts
Showing posts with label Shell Script. Show all posts

Wednesday, June 29, 2016

Using Spark for my routers and switches config backup

Not the most innovative idea in the world, but it works for me.  In my home and lab there are quite a number of routers and switches.  This is what I've configured on the devices to periodically upload the config to the FTP server

ip ftp source-interface
ip ftp username nms
ip ftp password nms
file prompt quiet
!
kron policy-list backup
 cli copy running-config ftp://10.1.5.98
!
kron occurrence daily-backup at 0:30 recurring
 policy-list backup

There is another script running on my Linux host to post these config files to Spark using the Spark Message API.  Good thing for Spark is it is persistent, and I can store the config files there as long as I want.


I do it for my development source code too, similar concept.


A script will be executed every night using the linux box cron job to get this done.  Or do it manually, by asking my chatbot to do it.

Tuesday, January 7, 2014

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: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


Saturday, February 2, 2008

JSP Execute shell script

Although there is security concern to do something like this, I might say that is convenient to do something like this instead of writing lots of complicated JSP pages to do simple system tasks.

Here ya go:

String linuxCmd = "./run.sh";
Runtime rt = Runtime.getRuntime();
rt.exec(linuxCmd);