Pages

Categories

Archives

[Google]

Sponsored Links

Script I wrote to switch payment processing companies

I wrote script below to allow support staff switch who we processed credit cards through. This was due to some not being able to process certain cards. The managers could change the name in this text file and script would switch processor and restart jboss and process cards. This allowed them to do it as needed without calling admins to do it. The kills are due to jboss not always wanting to exit properly. It could be done better, but this worked and I never got time to go fix it. I am posting this just as an example.

#!/bin/bash

#PATH

PATH=$PATH

 

#String we want to look for

STRING=”cardservices”

 

# NAME of the file to work with

FILE=”/cardservices/paymentoption.txt”

FILE2=”/usr/local/xxx/cardservices/paymentoption.change”

 

#String in the file

S1=`cat /cardservices/paymentoption.txt`

S2=`cat /usr/local/xxx/cardservices/paymentoption.change`

 

#Link to create

LINK=/home/jboss/server/default/deploy/properties-service.xml

CARDSERVICE=/usr/local/xxx/apps/home/jboss/server/default/deploy/properties-service.xml.live2_cardservicesonly

DHD=/usr/local/xxx/apps/home/jboss/server/default/deploy/properties-service.xml.live2

 

#LOG

LOG=/usr/local/xxx/cardservices/changes.log

DATE=$(date +%c)

JBOSS_PROCESS=”/usr/java/default/bin/java”

 

#DO NOT EDIT BELOW HERE

#DO NOT EDIT BELOW HERE

#DO NOT EDIT BELOW HERE

DO NOT EDIT BELOW HERE!!!

#Clean up the microsoft crap from people using windows because i like things uniform

dos2unix -l /cardservices/paymentoption.txt

 

#Check if file exists

if [ ! -f $FILE ];then

        echo “File doesn’t exist, please correct this issue”

else

        #If file exist we open the the files and compare the strings

        #if they do not match we remake the links if they do match we exit.

        if [ $S1 = $S2 ]; then

                echo “No changes detected”

        else

                if [ $S1 = $STRING ];then

                        rm -f $LINK;ln -s $CARDSERVICE $LINK;cp $FILE $FILE2

                        echo “Changed to properties-service.xml.live2_cardservicesonly on” $DATE >> $LOG

                        /etc/rc.d/init.d/jboss stop

 

                        #sleep between stop & starts

                        sleep 60

                        echo “Killing Jboss if still running”

                        ps ax | grep $JBOSS_PROCESS | grep -v grep | awk ‘{ print $1 }’ | xargs -i kill {} 2&>/dev/null

                        sleep 10

                        /etc/rc.d/init.d/jboss start

                        #sleep before sending the email

                        sleep 50

                        echo “Changed to Card Services on” $DATE | mail -s “Payment Option has changed” BigSearch@domain.com

                else

                        rm -f $LINK; ln -s $DHD $LINK;cp $FILE $FILE2

                        echo “Changed to properties-service.xml.live2 on” $DATE >> $LOG

                        /etc/rc.d/init.d/jboss stop

                        #sleep between stop & starts

                        sleep 60

                        echo “Killing Jboss if still running”

                        ps ax | grep $JBOSS_PROCESS | grep -v grep | awk ‘{ print $1 }’ | xargs -i kill {} 2&>/dev/null

                        sleep 10

                        /etc/rc.d/init.d/jboss start

                        #sleep before sending the email

                        sleep 50

                        echo “Changed to DHD on” $DATE | mail -s “Payment Option has changed” BigSearch@domain.com

                fi

        fi

 

fi

Comments are closed.