Wednesday, October 24, 2018

Script to create svn account

#!/usr/bin/env bash
PASSWORDFILE=/cm/websvn/conf/passwd
TEMPFILE=/tmp/$$
ALPHA="[A-z]"
NUM="[0-9]"
ALPHANUM="[A-z|0-9]"


if [ ${#} = 0 ]
then
    echo "You need to specify at least one username."
    exit
fi

# Allow for multiple names blank-separated (as usual) or comma-separated
for U in `echo ${*} | sed -e "s;,; ;g"`
do
    # Verify username is the right syntax (lowercase it first)
    USER=`echo ${U}| tr "[A-Z]" "[a-z]" | sed -e "s;@abc.com$;;"`
    echo ${USER} | grep "^${ALPHA}${ALPHA}${NUM}${NUM}${NUM}${ALPHANUM}$" >/dev/null 2>&1
    if [ ${?} = 0 ]
    then
        grep "^${USER}[     ]*=" ${PASSWORDFILE} >/dev/null 2>&1
        if [ ${?} != 0 ]
        then
            echo "Check this person's validity at http://webphone.abc.com/cgi-bin/ladder.pl?id=${USER}"
            echo -n "Add ${USER}?> "
            read INPUT
            if [ ! -z ${INPUT} ] && [ ${INPUT} = 'y' ]
            then
                touch ${TEMPFILE} ; chmod 600 ${TEMPFILE}
                ssh ecombuild02 "< /dev/urandom  tr -cd 'A-Za-z0-9' | head -c\${1:-8} ; echo" >${TEMPFILE} 2>/dev/null
                PW=`cat ${TEMPFILE}`
                rm -f ${TEMPFILE}
                echo "${USER} = ${PW}" >> ${PASSWORDFILE}
                echo -n "Subversion (svn) account created for ${USER}. "
                sendSvnPassword.sh ${USER}
            else
                echo "Skipped ${USER}"
            fi
        else
            echo -n "${USER} already has an account, re-send password?> "
            read INPUT
            if [ ! -z ${INPUT} ] && [ ${INPUT} = 'y' ]
            then
                sendSvnPassword.sh ${USER}
            fi
        fi
    else
        echo "${USER} is not the correct syntax for a username, ignoring."
    fi
    echo
done

nginx script


#!/bin/bash
##############################################################################
#
# Init script for Nginx webservers. Located in /sites/utils/local/bin.
#
##############################################################################

#Setup our base
BASEDIR=${BASEDIR:="/sites/utils/local"}

# Source the appctl-base file for common functions and ENV variables
[ -f $BASEDIR/lib/appctl-base ] && . $BASEDIR/lib/appctl-base

ULIMIT_MAX_FILES="$ULIMIT -S -n $($ULIMIT -H -n)"
# Set the maximum number of file descriptors allowed per child process.
if [ "x$ULIMIT_MAX_FILES" != "x" ]; then
    $ULIMIT_MAX_FILES
fi

INSTANCE=$1
COMMAND=$2
F5TOOL=$F5MEMBERSTATUS
CMDPREFIX=""

# Base webserver directory
WWW_BASE=/sites/www-site

# Directory for Pre/Post Event Hook scripts
HOOKS_DIR="$WWW_BASE/hooks"

OS_TYPE=$($UNAME)
if [ "$OS_TYPE" = 'SunOS' ]; then
    LD_LIBRARY_PATH=/usr/openwin/lib:/opt/sfw/lib:/usr/lib:/usr/local/lib:/usr/ccs/lib:/usr/4lib:$LD_LIBRARY_PATH:/$BASEDIR/lib:/sites/www-site/APACHE/lib
else # Linux
    LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib:/$BASEDIR/lib:/sites/www-site/APACHE/lib
fi
export LD_LIBRARY_PATH

# Use values from global_environment if they're defined. Otherwise use these defaults.
NGINX=${NGINX:-"/sites/utils/bin/nginx"}
CTLFILE=${CTL_INPUT_BOTHELLWEBS:-"/sites/utils/local/etc/ctl/ctl.input-bothellwebs"}

# Redefined in main
DATACENTER=''

#No trailing slash on CONFBASE, its added on by CONFDIR.
CONFBASE=${CONFBASE:-"/sites/www-site/conf"}
CONFDIR=${CONFDIR:-"$CONFBASE/$($ECHO $INSTANCE | $CUT -d - -f 1)"}
CFGFILE=${CFGFILE:-"${CONFDIR}/nginx-${INSTANCE}.conf"}

LOGDIR=${LOGDIR:-"/sites/www-site/logs"}
SSLDOMAINFILE=${SSLDOMAINFILE:-"/sites/utils/local/etc/ctl/webinstance-domain.conf"}
CHIPSETFILE=${CHIPSETFILE:-"/sites/utils/local/etc/ctl/webserver-chipset.conf"}
CERTSDIR=${CERTSDIR:-"/sites/www-site/prod_ssl_certs"}
OPENSSL=${OPENSSL:-"/sites/www-site/OPENSSL/openssl-1.0.0g-niagara2-64"}

#header vars
CLUSTER=$($GETCTLATTRIBUTE $CTLFILE ${HOSTNAME} $INSTANCE cluster)

#Source the override files, ultimately used to run different
# NGINX binaries and openssl libraries per-instance if necessary.

#instance-level override, synched
[ "$OS_TYPE" = 'SunOS' ] && [ -f $CONFDIR/webctl-override.cfg ] && readAndSourceFile $CONFDIR/webctl-override.cfg

#instance-level override, not synched.
[ -f /sites/www-site/$INSTANCE-override.cfg ] && readAndSourceFile /sites/www-site/$INSTANCE-override.cfg

# Number of days to keep log files if rotating
NUMDAYS=90

#Capture the A10 control passwords
A10USER=`$GETCREDENTIALS -i 201 -u 2>/dev/null`
A10PASS=`$GETCREDENTIALS -i 201 -p -d 2>/dev/null`

##
# Usage
###
usage() {
    $ECHO "Usage: $0 instancename <status|start|stop|reload|restart|kill|startsessions|stopsessions|killsessions|clearcache|flushlogs|rotatelogs>"
    return 1
}

##
# Escape quotes in a string
##
escapeQuotes() {
    $ECHO $1 | sed 's/"/\\"/g'
}

##
# Get PIDS
###
getPids() {
    BASECFGFILE=$($BASENAME $CFGFILE)
    CMD="$PS auxwww | $EGREP \"^ *(www|root).*nginx.*$BASECFGFILE\" | $GREP -v grep"
    if [ "$ME" = "atg" ]
    then
        CMD="$CMDPREFIX \"$(escapeQuotes "$CMD")\""
    fi
    eval $CMD | awk '{print $2}'
}

setupEnv() {
        ROOTDIR=`dirname $NGINX`
        ROOTDIR="$ROOTDIR/../"

    NGINX_CMD="X_CLUSTER=$CLUSTER X_INSTANCE=$INSTANCE X_HOST=${HOSTNAME} $NGINX -p ${WWW_BASE} -c $CFGFILE"
}

##
# Start or Stop
###
startOrStopCmd() {
    command=$1
    rval=""

    setupEnv

    if [ "$command" = "start" ]; then
        # Clear log symlinks
        $CMDPREFIX "$FIND ${LOGDIR}/ -maxdepth 1 -type l -regex \".*[-_]${INSTANCE}\.log\" -delete"

        #Echo the startup logs into what would be the error log
        #TODO: Disabled as this script doesn't have perms to write to that file.
        #echoReadFiles >> $LOGDIR/error_${INSTANCE}.log
        # Pass the SSL cert value on the command line.
        # If no value was defined then SSLSTRING is empty.
        $CMDPREFIX "${NGINX_CMD}"

        if [ $? -eq 0 ]; then
            $ECHO "NGINX started."
            rval=0
        else
            $ECHO "NGINX failed to start."
            rval=1
        fi

    elif [ "$command" = "stop" ]; then
        MESSAGE=
        RVAL=

        $CMDPREFIX "${NGINX_CMD} -s stop"
        if [ $? -eq 0 ]; then
            [ -z "$MESSAGE" ] && export MESSAGE="NGINX is being stopped."
            [ -z "$RVAL" ] && export RVAL=0
        else
            export MESSAGE="NGINX failed to stop."
            export RVAL=1
        fi
        $ECHO $MESSAGE
    fi
    return $RVAL
}

##
# Kill Command
###
killCmd() {
    stat="x"
    for pass in 1 2; do
        pids=$(getPids)
        if [ "$pass" -eq 1 -a -z "$pids" ]; then
            stat="x0"
            break
        else
            for p in $pids; do
                $ECHO "killing process $p..."
                if [ "$ME" = "atg" ]; then
                    sudo su - www -c "$KILL -KILL $p"
                else
                    $KILL -KILL $p
                fi
            done
        fi

        # Sleep and do another kill because first try doesn't always work.
        $SLEEP 5
    done

    if [ "$stat" = "x" ]; then
        return 0
    else
        $ECHO "No processes to kill."
        return 1
    fi
}

##
# Output status of instance for F5 and Apache
###
fullStatus() {
    [ $# -ne 1 ] && $ECHO 1>&2 "Incorrect # of fullStatus arguments" && exit 1
    INSTANCE_NAME=$1
    F5STATUS=$(f5Status $INSTANCE_NAME)
    F5RETCODE=$?
    APACHESTATUS=$(getStatus)
    ARETCODE=$?
    $ECHO "$F5STATUS $APACHESTATUS"
    [ $F5RETCODE -ne 0 ] && return 1
    return $ARETCODE
}

##
# Get Status
###
getStatus() {
    pids=$(getPids)
    if [ -n "$pids" ]; then
        $ECHO "NGINX is running."
        return 0
    else
        $ECHO "NGINX is not running."
        return 1
    fi
}


##
# Get server chipset,used to choose which apache subversion to run
##

getChipset() {
    [ ! -e $CHIPSETFILE ] && $ECHO 1>&2 "Could not find chipset file" && return
    ARCH=$($PRTCONF | $HEAD -5 | $TAIL -1 | $CUT -d, -f2)
    [ -z "$ARCH" ] && $ECHO 1>&2 "Could not find architecture" && return
    CHIPSET=$($GREP -w "$ARCH" $CHIPSETFILE | $CUT -d, -f2 | $HEAD -1)
    [ -z "$CHIPSET" ] && $ECHO 1>&2 "Could not find $ARCH in $CHIPSETFILE" && return
    $ECHO "$CHIPSET"
}

##
# Get chipspecific version
#  Take a path and attempt to find a processor specific version of it.
#  such as OPENSSL, or httpd.  If the specified location cannot be found then blows up.
# Accepts the @CHIPSET@ macro
##

getChipsetSpecificPath() {
    [ $# -ne 1 ] && $ECHO 1>&2 "Incorrect # of getChipsetSpecificPath arguments" && exit 1
    #If no chipset is found, default to niagara
    # If no target is found with that chipset, try blank
    TARGET=$1
    CHIPSET=`getChipset`

    for x in -$CHIPSET -niagara ''; do
        TMPTARGET=$TARGET
        TMPTARGET=${TMPTARGET//@CHIPSET@/$x}
        [ -e $TMPTARGET ] && $ECHO $TMPTARGET && return
    done

    #If we are here then nothing matched
    $ECHO 1>&2 "Could not find matching target for $TARGET" && exit 1
}

##
# Stop Sessions
# F5s do stopsessions via SOAP. A10s do it via changing the healthcheck file.
###
stopSessions() {
    [ $# -ne 1 ] && $ECHO 1>&2 "Incorrect # of stopSessions arguments" && exit 1
    INSTANCE_NAME=$1
    ADDRESS=$(getAddress)

    callHelper $HOOKS_DIR/$PRE_STOP_SESSIONS

    $ECHO "Stopping sessions of $INSTANCE_NAME"
    ERROR=0
    pools=$(getF5Pools $INSTANCE_NAME)

    touch /sites/utils/tmp/$INSTANCE_NAME.disable && $CHMOD 666 /sites/utils/tmp/$INSTANCE_NAME.disable

    for POOLINFO in $pools; do
        F5SERVER=$($ECHO $POOLINFO | $CUT -d\| -f 1)
        F5POOL=$($ECHO $POOLINFO | $CUT -d\| -f 2)
        #POOL example: pSTANDALONE_443,
        PORT_STUB=$($ECHO $POOLINFO | $SED -e 's/_/ /g' | $AWK '{print $NF}')
        # 443/ 80 for most, or 19443 for fulfillment

        #fulfillment, vend pool names are their exact listening port.
        if [ $PORT_STUB -gt 999 ]; then
            PORT=$PORT_STUB
        else
            # Some virtual servers listen on high ports, so we check for
            PORT=$(( $($ECHO $INSTANCE | $CUT -d"-" -f2) * 1000 + $PORT_STUB ))
        fi

        #Determine if this is a a10 or F5 call
        expr "$F5POOL" : "ap" >/dev/null && IS10=1


        if [ -n "$IS10" ]; then
            #Enable the port, in case it was previously disabled
            SESSIONID=`$WGET "https://$F5SERVER/services/rest/V1.1/?method=authenticate&username=${A10USER}&password=${A10PASS}"  --no-check-certificate -O- -q | $CUT -d\< -f 4 | $CUT -d\> -f 2`
            $WGET "https://$F5SERVER/services/rest/V1.1/?session_id=$SESSIONID&method=slb.server.update&address=$ADDRESS&port-list=port1&port1=port_num%03$PORT%02protocol%032%02status%031"  --no-check-certificate -O- -q |xmllint --format -| $GREP -w ok >/dev/null 2>&1
            RESULT=$?
            $ECHO "$F5SERVER:$PORT state set to 'STATE_DISABLED/STATE_ENABLED"
            if [ $RESULT -eq 0 ]; then
                $ECHO "Suspend returned success for $F5SERVER|$F5POOL"
            else
                $ECHO "Suspend failed for $F5SERVER|$F5POOL"
            fi
        else
            $F5TOOL $F5SERVER $F5POOL $ADDRESS:$PORT disable
            RETCODE=$?

            if [ $RETCODE -ne 0 ]; then
                $ECHO "ERROR: disable returned nonzero returncode for $POOLINFO"
                let ERROR=ERROR+1
            else
                $ECHO "Suspend returned success for $POOLINFO"
            fi
        fi
    done


    callHelper $HOOKS_DIR/$POST_STOP_SESSIONS

    return $ERROR
}

##
# Start Sessions
###
startSessions() {
    [ $# -ne 1 ] && $ECHO 1>&2 "Incorrect # of startSessions arguments" && exit 1
    INSTANCE_NAME=$1
    ADDRESS=$(getAddress)

    callHelper $HOOKS_DIR/$PRE_START_SESSIONS

    $ECHO "Starting sessions of $INSTANCE_NAME"
    ERROR=0

    pools=$(getF5Pools $INSTANCE_NAME)
    [[ -e  /sites/utils/tmp/$INSTANCE_NAME.disable ]] && rm -f /sites/utils/tmp/$INSTANCE_NAME.disable

    for POOLINFO in $pools; do
        F5SERVER=$($ECHO $POOLINFO | $CUT -d\| -f 1)
        F5POOL=$($ECHO $POOLINFO | $CUT -d\| -f 2)
        #POOL example: pSTANDALONE_443,
        PORT_STUB=$($ECHO $POOLINFO | $SED -e 's/_/ /g' | $AWK '{print $NF}')
        # 443/ 80 for most, or 19443 for fulfillment

        #fulfillment, vend pool names are their exact listening port.
        if [ $PORT_STUB -gt 999 ]; then
            PORT=$PORT_STUB
        else
            # Some virtual servers listen on high ports, so we check for
            PORT=$(( $($ECHO $INSTANCE | $CUT -d"-" -f2) * 1000 + $PORT_STUB ))
        fi

        #Determine if this is a a10 or F5 call
        expr "$F5POOL" : "ap" >/dev/null && IS10=1


        if [ -n "$IS10" ]; then
            SESSIONID=`$WGET "https://$F5SERVER/services/rest/V1.1/?method=authenticate&username=${A10USER}&password=${A10PASS}"  --no-check-certificate -O- -q | cut -d\< -f 4 | cut -d\> -f 2`
            $WGET "https://$F5SERVER/services/rest/V1.1/?session_id=$SESSIONID&method=slb.server.update&address=$ADDRESS&port-list=port1&port1=port_num%03$PORT%02protocol%032%02status%031"  --no-check-certificate -O- -q |xmllint --format -| $GREP -w ok >/dev/null 2>&1
            RESULT=$?
            $ECHO "$F5SERVER:$PORT state set to 'STATE_ENABLED/STATE_ENABLED"
            if [ $RESULT -eq 0 ]; then
                $ECHO "Enable returned success for $F5SERVER|$F5POOL"
            else
                $ECHO "Enable failed for $F5SERVER|$F5POOL"
            fi
        else
            $F5TOOL $F5SERVER $F5POOL $ADDRESS:$PORT enable
            RETCODE=$?

            if [ $RETCODE -ne 0 ]; then
                $ECHO "ERROR: enable returned nonzero returncode for $POOLINFO"
                let ERROR=ERROR+1
            else
                $ECHO "Enable returned success for $POOLINFO"
            fi
        fi
    done


    callHelper $HOOKS_DIR/$POST_START_SESSIONS

    return $ERROR
}

##
# Kill Sessions
###
killSessions() {
    [ $# -ne 1 ] && $ECHO 1>&2 "Incorrect # of startSessions arguments" && exit 1
    INSTANCE_NAME=$1
    ADDRESS=$(getAddress)

    callHelper $HOOKS_DIR/$PRE_KILL_SESSIONS

    $ECHO "Killing sessions of $INSTANCE_NAME"
    ERROR=0

    touch /sites/utils/tmp/$INSTANCE_NAME.disable && $CHMOD 666 /sites/utils/tmp/$INSTANCE_NAME.disable

    pools=$(getF5Pools $INSTANCE_NAME)
    for POOLINFO in $pools; do
        F5SERVER=$($ECHO $POOLINFO | $CUT -d\| -f 1)
        F5POOL=$($ECHO $POOLINFO | $CUT -d\| -f 2)
        #POOL example: pSTANDALONE_443,
        PORT_STUB=$($ECHO $POOLINFO | $SED -e 's/_/ /g' | $AWK '{print $NF}')
        # 443/ 80 for most, or 19443 for fulfillment

        #fulfillment, vend pool names are their exact listening port.
        if [ $PORT_STUB -gt 999 ]; then
            PORT=$PORT_STUB
        else
            # Some virtual servers listen on high ports, so we check for
            PORT=$(( $($ECHO $INSTANCE | $CUT -d"-" -f2) * 1000 + $PORT_STUB ))
        fi

        #Determine if this is a a10 or F5 call
        expr "$F5POOL" : "ap" >/dev/null && IS10=1

        if [ -n "$IS10" ]; then
            #Remove the disable file and enable the port, in case it was previously disabled
            SESSIONID=`$WGET "https://$F5SERVER/services/rest/V1.1/?method=authenticate&username=${A10USER}&password=${A10PASS}" --no-check-certificate -O- -q | cut -d\< -f 4 | cut -d\> -f 2`
            $WGET "https://$F5SERVER/services/rest/V1.1/?session_id=$SESSIONID&method=slb.server.update&address=$ADDRESS&port-list=port1&port1=port_num%03$PORT%02protocol%032%02status%030"  --no-check-certificate -O- -q |xmllint --format -| $GREP -w ok >/dev/null 2>&1
            RESULT=$?
            $ECHO "$F5SERVER:$PORT state set to 'STATE_DISABLED/STATE_DISABLED"
            if [ $RESULT -eq 0 ]; then
                $ECHO "Kill returned success for $F5SERVER|$F5POOL"
            else
                $ECHO "Kill failed for $F5SERVER|$F5POOL"
            fi
        else

            $F5TOOL $F5SERVER $F5POOL $ADDRESS:$PORT kill
            RETCODE=$?

            if [ $RETCODE -ne 0 ]; then
                $ECHO "ERROR: Kill returned nonzero returncode for $POOLINFO"
                let ERROR=ERROR+1
            else
                $ECHO "Kill returned success for $POOLINFO"
            fi
        fi
    done

    callHelper $HOOKS_DIR/$POST_KILL_SESSIONS

    return $ERROR
}

##
# Restart Monitor Scripts
###
restartMonitors() {
    $WLTAILER stop
    $SNMPSUBAGENT stop
    $SLEEP 2
    $PS -ef | $EGREP '(jmxgetbea|snmpsuba)'| $AWK '{print $2}' | $XARGS $KILL
    $SLEEP 2
    $WLTAILER start
    $SLEEP 2
    $SNMPSUBAGENT start
}

##
# Rotate Logs
###
rotateLogs() {
    logs=$($LS $LOGDIR/*${INSTANCE}.log 2>/dev/null)
    if [ -n "$logs" ]; then
        local dt=$($DATE +%Y%m%d)
        for log in $logs; do
            log=$(basename $log)
            $CMDPREFIX "$MV $LOGDIR/$log $LOGDIR/archives/$log-$dt"
            if [ $? -ne 0 ]; then
                echo "Could not move file $log to archives"
                return 1
            fi
            $CMDPREFIX "$NICE $GZIP -f $LOGDIR/archives/$log-$dt </dev/null >/dev/null 2>/dev/null &"
        done
    else
        $ECHO "No logs to rotate"
        return 1
    fi

    # tell nginx to rotate logs
    setupEnv
    $CMDPREFIX "${NGINX_CMD} -s reopen"
}

##
# Flush Logs from memory
##
flushLogs() {
    echo 'Flushing nginx logs.'
        setupEnv
        $CMDPREFIX "${NGINX_CMD} -s reopen"
}

##
# Reload nginx
##
reloadNginx() {
    echo 'Reloading nginx process.'
    setupEnv
    $CMDPREFIX "${NGINX_CMD} -s reload"   
}

clearCache() {
    local envname="$($ECHO $INSTANCE | $CUT -d - -f 1)"
    echo "Clearing cache by rm /tmp/.nginx_*_$INSTANCE /sites/utils/tmp/.nginx_*_$INSTANCE /tmp/.nginx_*_$envname /sites/utils/tmp/.nginx_*_$envname"
    $CMDPREFIX "rm -rf /tmp/.nginx_*_$INSTANCE /sites/utils/tmp/.nginx_*_$INSTANCE /tmp/.nginx_*_$envname /sites/utils/tmp/.nginx_*_$envname"
    reloadNginx   
}

##
# Main
###
main() {
    # Check that command line was complete
    if [ ! -n "$INSTANCE"  -o  ! -n "$COMMAND" ]; then
        usage
        exit $?
    fi

    # Must be run as atg, www or root
    if [ "$ME" != "root" -a "$ME" != "www" -a "$ME" != 'atg' ]; then
        $ECHO "You must be root or the www or atg user to run this script."
        exit 1
    fi

    # Check that required tools work
    for x in CTLATTRIBUTETOOL WGET PS; do
        eval value=\$$x
        if [ ! -x "$value" ]; then
            $ECHO "Unable to execute $x: $value, results indeterminate" >&2
            exit 1
        fi
    done

    # Check for F5 tool
    if [ ! -f $F5TOOL ]; then
        $ECHO "Not found F5TOOL: $F5TOOL , aborting." >&2
        exit 1
    fi

    # Check for config file's existence
    if [ ! -e $CFGFILE ]; then
        $ECHO "$CFGFILE not found, aborting." >&2
        exit 1
    fi

    ###
    # If we are on privileged port (< 1024) then run as root, otherwise we'll run as www in the command prefix.
    # This will ignore lines that start with a # in the first column.
    ###

    # get list of ports this instance listens on
    LISTENPORTS=$($GREP -E '^[\t ]*Listen[\t ]+' $CFGFILE | $SED 's/^[ \t]*Listen[\t ]*//' | $SED 's/[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*://')

    # cycle through list and see if any are privileged
    ROOT=0
    LISTEN=0
    for port in $LISTENPORTS
    do
        LISTEN=1
        [ $port -lt 1024 ] && ROOT=1
    done

    if [ $LISTEN -eq 1 ]; then
        if [ $ROOT -eq 1 ]; then
            if [ "$ME" = "root" ]; then
                CMDPREFIX="$SH -c"
            else
                $ECHO "Listen port is privileged and this script was not run as root.  Aborting."
                exit 1
            fi
        else
            if [ "$ME" = "www" ]; then
                CMDPREFIX="$SH -c"
            elif [ "$ME" = 'root' ]; then
                CMDPREFIX="$SU - www -c"
            else
                CMDPREFIX="$SUDO $SU - www -c"
            fi
        fi
    else # for some reason we did not find a Listen port so default to using sudo
        CMDPREFIX="$SUDO $SU - www -c"
    fi


    # Define DATACENTER and verify it is set.
    DATACENTER=${DATACENTER:-$($CTLATTRIBUTETOOL $CTLFILE $HOSTNAME $INSTANCE datacenter)}
    if [ -z "$DATACENTER" ]; then
        $ECHO "No datacenter defined for this instance --  update the ctl input file. Aborting." >&2
        exit 1
    fi

    # Get the chipset specific httpd,openssl
    if [ "$OS_TYPE" = 'SunOS' ]; then
        NGINX=`getChipsetSpecificPath $NGINX`
        OPENSSL=`getChipsetSpecificPath $OPENSSL`
    fi

    LD_LIBRARY_PATH=$OPENSSL/lib:$LD_LIBRARY_PATH
    export LD_LIBRARY_PATH

    # Process Command
    case $COMMAND in
        start|stop) startOrStopCmd $COMMAND; exit $?
        ;;
        reload) reloadNginx; exit $?
        ;;
        restart) startOrStopCmd stop; sleep 5; startOrStopCmd start; exit $?
        ;;
        kill) killCmd; exit $?
        ;;
        status) fullStatus $INSTANCE; exit $?
        ;;
        f5status) f5Status $INSTANCE; exit $?
        ;;
        restartmonitors) restartMonitors; exit $?
        ;;
        startsessions) startSessions $INSTANCE; exit $?
        ;;
        stopsessions) stopSessions $INSTANCE; exit $?
        ;;
        killsessions) killSessions $INSTANCE; exit $?
        ;;
        clearcache) clearCache; exit $?
        ;;
        flushlog|flushlogs) flushLogs; exit $?
        ;;
        rotatelog|rotatelogs) rotateLogs; exit $?
        ;;
        help|*) usage; exit 1
        ;;
    esac
}

## Main ##
main $@

Script to add/remove init scripts and rc*.d links for programs using ctl scripts.

#!/bin/bash
###################################################################################
#
# ctlrc.sh
#
# Script to add/remove init scripts and rc*.d links for programs using ctl scripts.
#
# Relies on etc/ctlrc.conf for configuration
#
# @(#)$Id$
# $URL$
###################################################################################

#Setup our base
BASEDIR=/sites/utils/local

# Load TAPS globals
source $BASEDIR/lib/loadglobals.sh
[ $? -ne 0 ] && exit 1

TYPE=""
INSTANCE=""
ACTION_ADD=0
ACTION_RM=0
ACTION_LIST=0
AUTO=0
VERBOSE=0
STARTDIR="rc3.d"
STOPDIRS="rc0.d rc1.d rc2.d"
CONF="$BASEDIR/etc/ctlrc.conf"
ETC="/etc"

##
# Usage
###
usage() {
    $ECHO "Usage: $0 -a -i <instance> -t <type> -[yv]"
    $ECHO "       $0 -r -i <instance> -t <type> -[yv]"
    $ECHO "       $0 -l"
    $ECHO "       -a    Add init script and links"
    $ECHO "       -r    Remove init script and links"
    $ECHO "       -t    Type of init script (use -l to find available types)"
    $ECHO "       -l    List available types"
    $ECHO "       -i    Instance name"
    $ECHO "       -y    Run without confirmation prompt"
    $ECHO "       -v    Verbose output"
    exit $1
}

##
# Get Types
###
getTypes() {
    types=`$GREP -v ^# $CONF | $AWK -F: '{print $1}'`
    $ECHO $types
}

##
# Confirm
###
confirm() {
        action=$1
    if [ $AUTO -ne 0 ]; then
        return 0
    fi
      $ECHO "Will $action script $initFile"
        $ECHO "Will $action link $initSFile"
        for dir in $STOPDIRS; do
            $ECHO "Will $action link ${ETC}/${dir}/${initKFile}"
        done
        $PRINTF "Do you wish to continue? [yN] "
        read confirm
        if [ "$confirm" != "y" -a "$confirm" != "Y" ]; then
            return 1
        else
            return 0
        fi
}

##
# Add All
###
addAll() {
    confirm "add" || return 1
        if [ $VERBOSE -eq 1 ]; then
        $ECHO "Creating init script $initFile";
        fi
        $CAT >$initFile 2>&1 <<EOF
#!/bin/sh
# This script is autogenerated by /sites/utils/local/bin/ctlrc

INSTANCE=$INSTANCE
CTL=$ctlScript

if [ ! -x "\$CTL" ]; then
    $ECHO "Unable to locate \$CTL"
    exit 2
fi

exec \$CTL \$INSTANCE \$1
EOF
        [ $? -ne 0 ] && return 1
        if [ $VERBOSE -eq 1 ]; then
            $ECHO "Setting execute permissions on $initFile"
        fi
       
        $CHMOD 755 $initFile
        if [ $VERBOSE -eq 1 ]; then
            $ECHO "Creating symlink to $initSFile"
        fi
       
        $LN -s $initFile $initSFile
        [ $? -ne 0 ] && return 1
       
        for dir in $STOPDIRS; do
        t=${ETC}/${dir}/${initKFile}
            if [ $VERBOSE -eq 1 ]; then
                $ECHO "Creating symlink to $t"
            fi
            $LN -s $initFile $t
            [ $? -ne 0 ] && return 1
        done
       
        return 0
}

##
# Remove All
###
removeAll() {
    confirm "remove" || return 1

    if [ -f $initFile ]; then
        if [ $VERBOSE -eq 1 ]; then
            $ECHO "Removing $initFile"
        fi
        $RM -f $initFile || return 1
    fi

    if [ -h $initSFile ]; then
        if [ $VERBOSE -eq 1 ]; then
            $ECHO "Removing $initSFile"
        fi
        $RM -f $initSFile || return 1
    fi

    for dir in $STOPDIRS; do
        t="${ETC}/${dir}/${initKFile}"
        if [ -h $t ]; then
            if [ $VERBOSE -eq 1 ]; then
                $ECHO "Removing $t"
            fi
            $RM -f $t || return 1
        fi
    done
    return 0
}

##
# Check Arguments
###
checkArgs() {
    if [ $ACTION_LIST -eq 1 ]; then
        return 0
    elif [ $ACTION_ADD -eq 1 -a $ACTION_RM -eq 1 ]; then
        $ECHO "Option -a and -r are not compatible"
        return 1
    elif [ -z "$TYPE" ]; then
        $ECHO "You must provide a type"
        return 1
    elif (! $GREP ^$TYPE $CONF >/dev/null 2>&1); then
        $ECHO "No such type $TYPE"
        return 1
    elif [ "$instanceRequired" -eq 1 -a ! "$INSTANCE" ]; then
        $ECHO "You must provide an instance name"
        return 1
    fi
    return 0
}

### Main ###

# Check command line options
[ $# -eq 0 ] && usage 1

while getopts t:i:arlyvh op; do
    case $op in
        t) TYPE=$OPTARG
            ;;
        i) INSTANCE=$OPTARG
            ;;
        a) ACTION_ADD=1
            ;;
        r) ACTION_RM=1
            ;;
        l) ACTION_LIST=1
            ;;
        y) AUTO=1
            ;;
        v) VERBOSE=1
            ;;
        h) usage 0
            ;;
        *) usage 1
            ;;
    esac
done

instanceRequired=`$GREP ^$TYPE $CONF | $CUT -d: -f2`

checkArgs || usage 1

baseName=`$GREP ^$TYPE $CONF | $CUT -d : -f 3`
priority=`$GREP ^$TYPE $CONF | $CUT -d : -f 4`
ctlScript=`$GREP ^$TYPE $CONF | $CUT -d : -f 5`

if [ -z "$INSTANCE" ]; then
    initFile=${ETC}/init.d/${baseName}
    initSFile=${ETC}/${STARTDIR}/S${priority}${baseName}
    initKFile=K${priority}${baseName}
else
    initFile=${ETC}/init.d/${baseName}_${INSTANCE}
    initSFile=${ETC}/${STARTDIR}/S${priority}${baseName}_${INSTANCE}
    initKFile=K${priority}${baseName}_${INSTANCE}
fi

if [ $ACTION_LIST -eq 1 ]; then
    getTypes
    exit $?
elif [ $ACTION_ADD -eq 1 ]; then
    addAll
    exit $?
elif [ $ACTION_RM  -eq 1 ]; then
    removeAll
    exit $?
fi

Common UNIX scripts

#!/bin/bash

IFS=$'\n'
sum_result=`ctl -C "$@" -a type=weblogic -q -m "fgrep 'Server state changed' /sites/servers/@INSTANCE@/logs/console.log | tail -1" | sed 's/Result://g'`;
sum_result=${sum_result/Result:/};

for result in $sum_result;
do
  echo $result;
done;

==========================
To find out status

==========================
#!/bin/bash

IFS=$'\n'
sum_result=`ctl -C "$@" -a type=weblogic -q -m "fgrep 'Server state changed' /sites/servers/@INSTANCE@/logs/console.log | tail -1" | sed 's/Result://g'`;
sum_result=${sum_result/Result:/};

for result in $sum_result;
do
  echo $result;
done;

==========================
To find 
==========================

_user='admin'
_pass='Rm0nly!'
_host=stg1b2cdserv01.cingular.com
_port=8210

curl -u "${_user}:${_port}" "http://${_host}:${_port}/system/att/dcs-tool?job=301template-for-detailspages&src=/content/att/shop&dest=/content/att&product-type=device&platform=desktop&tag=1407Ma_supplement&dryrun=y" > out.json


==========================
DB Connect Script

==========================


#!/bin/bash

SCRIPT_HOME=/sites/utils/local/bin
ORACLE_HOME=/opt/oracle/product/10.2.0/client_1
ORACLE_SID=tapsdb1.world
CONFIG=$SCRIPT_HOME/config/



$ORACLE_HOME/bin/sqlplus -s <<! 2>&1 > $LOG_FILE
  ${SB_LOGIN}/${SB_PWD}@${ORACLE_SID}


==========================
JDBC Info 

==========================
#!/bin/bash
# @(#)$Id: jdbcinfo.sh 53624 2008-05-21 22:56:52Z jw089a $
# Wrapper script for jdbcinfo.py.

WL_BASE=$(/sites/utils/local/libexec/findWL.sh mjobA) || { echo "$WL_BASE"; exit 1; }
WLST=$WL_BASE/common/bin/wlst.sh
SCRIPT=/sites/utils/local/bin/jdbcinfo.py
USER=
PASSWORD=
PORT=
RESOURCE=

usage()
{
    echo "Usage: $0 -u username -p password -P port -r resource"
    exit $1
}

if [ $# -ne 8 ]; then
    usage 1
fi
while getopts hu:p:P:r: opt; do
    case $opt in
    h) usage 0;;
    u) USER=$OPTARG;;
    p) PASSWORD=$OPTARG;;
    P) PORT=$OPTARG;;
    r) RESOURCE=$OPTARG;;
    esac
done

out=`$WLST $SCRIPT -u $USER -p $PASSWORD -P $PORT -r $RESOURCE | grep '^DB'` || exit $?
for line in $out; do
    echo $line
done
exit 0

Sunday, October 14, 2018

Artificial Intelligence course from MIT in 6 weeks



Orientation Module: Welcome to Your Online Campus


You’ll be welcomed with a personal call and get introduced to your online teaching and technical support network. Begin connecting with fellow participants while exploring the navigation and tools of your Online Campus. Be alerted to key milestones in the learning path, and review how your results will be calculated and distributed. You’ll be required to complete your participant profile, confirm your certificate delivery address, and submit a digital copy of your passport/identity document.



Module 1: An Introduction to Artificial Intelligence


This introductory module guides you through the evolution of key AI technologies and how they have developed to transform industry and business practice. The relationship between AI and collective intelligence, as well as the implications of this partnership for business strategy and society are also introduced. As part of an ongoing project, you’ll begin to consider your own organization in terms of the application of AI technologies.




Module 2: Machine Learning in Business

In this module, you’ll explore the core concepts of machine learning – an AI technology which aims to design, understand, and use computer programs to learn from experience. Discover how machine learning can be successfully integrated into business functions through rich case studies and faculty-led videos that examine the opportunities that this subfield of AI affords. For your ongoing project, you’ll propose ideas for the application of machine learning in a business context of your choice.




Module 3: Natural Language Processing in Business


This module is devoted to natural language processing (NLP), an AI technology developed to intelligently process human language. Through rich case studies and faculty-led videos, which explore functions such as machine translation, summarization, and sentiment analysis, you’ll learn how NLP can be skillfully deployed in a series of business contexts. For the next part of your project, the focus will shift to NLP and its strategic implementation in a business context of your choice.




Module 4: Robotics in Business


This module delves into the key elements of robotics as a transformative AI technology, with a focus on automating processes and tasks. Through rich case studies and facultyled videos that survey robots and autonomous vehicles, you’ll learn how robotics can benefit an organization. You’ll have the opportunity, once more, to submit ideas regarding the potential for robotics to be deployed in a business context of your choice.




Module 5: Artificial Intelligence in Business and Society


In this module, you’ll see examples of other kinds of AI as well as return to collective intelligence and the human-machine relationship. Here you’ll also consider the impact of AI on jobs, and the ethical and social implications of AI integration. You’ll be tasked with anticipating and planning for the risks and considerations that may apply to integrating AI in a business context of your choice.




Module 6: The Future of Artificial Intelligence


This module will allow you to imagine the future of AI and its potential use in your organization. Using what you have learned from the previous modules, you’ll create a business roadmap for the strategic implementation of AI and collective intelligence into an organization of your choice.




Hyderabad Trip - Best Places to visit

 Best Places to Visit  in Hyderabad 1.        1. Golconda Fort Maps Link :   https://www.google.com/maps/dir/Aparna+Serene+Park,+Masj...