• CozWeAreFriends Banner. Nice isn't it?
  • CozWeAreFriends Banner. Nice isn't it?
  • Siebel Restart WebServer Script When Memory Reaching Threshold

    Posted on April 27th, 2012 by fath

    Hello All,

    There’s this occasion whereby Siebel will somehow crash if the server memory reaching certain level. To encounter/as a workaround for this, I wrote a monitoring script that will check the server utilization and perform Siebel’s WebServer restart whenever only small amount of memory left in the server. Please have a look at the script below 🙂

     

    #!/usr/bin/sh
    # Script to grep Free RAM
    # Perform Web Server restart once the RAM meet threshold
    # Written by Fath

    # THRESHOLD IN ‘K’ bytes UNIT
    THRESHOLD=1400000

    WEB_SERVICE_DIR=/opt/hpws/apache32/bin

    FREE_RAM_OUTPUT=/home/admin/FREE_RAM_OUTPUT.txt
    TOP_OUTPUT=/home/admin/TOP_OUTPUT.txt
    top -d1 -f ${TOP_OUTPUT}

    MEMORY_ALL=`grep “Memory:” ${TOP_OUTPUT}`
    FREE_RAM=`echo ${MEMORY_ALL} | awk ‘{print $8}’`
    FREE_RAM_NO=`echo $FREE_RAM | awk ‘{gsub (/K/,””); print}’`

    echo “———————————————–” >> ${FREE_RAM_OUTPUT}
    date >> ${FREE_RAM_OUTPUT}

    if [ “$FREE_RAM_NO” -lt “$THRESHOLD” ];then
    echo “Free RAM is less than ${THRESHOLD}K (${FREE_RAM_NO}K). Performing Web Service restart…” >> ${FREE_RAM_OUTPUT}
    echo “httpd processes running in server:” >> ${FREE_RAM_OUTPUT}
    ps -ef | grep httpd | grep apache32 >> ${FREE_RAM_OUTPUT}
    echo “Shutting down.. ” >> ${FREE_RAM_OUTPUT}
    . ${WEB_SERVICE_DIR}/stopapa >> ${FREE_RAM_OUTPUT}
    sleep 1
    PROC_COUNT=`ps -ef | grep httpd | grep apache32 | wc -l`
    while [ “$PROC_COUNT” -ne “0” ]
    do
    sleep 1
    PROC_COUNT=`ps -ef | grep httpd | grep apache32 | wc -l`
    done
    echo “0 httpd process running. Starting up..” >> ${FREE_RAM_OUTPUT}
    . ${WEB_SERVICE_DIR}/startapa >> ${FREE_RAM_OUTPUT}
    while [ “$PROC_COUNT” -eq “0” ]
    do
    sleep 1
    PROC_COUNT=`ps -ef | grep httpd | grep apache32 | wc -l`
    done
    echo “OK! httpd processes are running!” >> ${FREE_RAM_OUTPUT}
    else
    echo “There’s enough free RAM (${FREE_RAM_NO}K).” >> ${FREE_RAM_OUTPUT}
    fi

    echo “———————————————–” >> ${FREE_RAM_OUTPUT}
    rm ${TOP_OUTPUT}

     



    UNIX – Shell script to create XMLs based on user input data

    Posted on April 26th, 2012 by fath

    Hi All,

    I wrote a simple shell script that can read parameterized XML structure and will generate completed XMLs (with correct values) based on what we specified in the input data. This script was actually meant for my initial phase of Performance Testing data loading in my project.

    To accomplish this, I created 3 files which are the script itself, the parameterized XML template, as well as the data file. Below are the files:

    1) structure.txt (XML template) – here I replaced the value of the field that we need to parameterize with variable, such as ${ACC_NUM}

    <Sbsc xmlns=”http://www.cozwearefriends.com/XMLSchema” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://www.cozwearefriends.com/XMLSchema XXX_Subsc
    ribers.xsd”>
    <ActSbsc id=”${ACC_NUM}”>
    <Act>
    <ActNo>${ACC_NUM}</ActNo>
    <Curr>${LOG}</Curr>
    <CustSegList/>
    <SubSta>A</SubSta>
    <BType>B</Btype>
    <Eff>2011-08-01T01:22:15-07:00</Eff>
    <CrtT>2011-08-01T01:22:15-07:00</CrtT>
    <ANArr elem=1>
    </Act>
    </ActSbsc>
    </Sbsc>

    2) createXML.sh (Shell script)

    # Script to create XML
    # based on user input
    # created by Fath

    STRUCTURE_FILE=structure.txt
    INPUT_FILE=input.txt
    OUTPUT_FILE=output.xml

    LOOP_NUMBER=`cat ${INPUT_FILE} | wc -l`

    i=1
    while [ “$i” -lt “$LOOP_NUMBER+1” ]
    do
    ACC_NUM=`head -${i} ${INPUT_FILE} | tail -1 | cut -f1 -d’;’`
    LOG=`head -${i} ${INPUT_FILE} | tail -1 | cut -f2 -d’;’`
    # Add in more variable here as well as in the command below if you have more than 2 parameters

    cat ${STRUCTURE_FILE} | sed -e s/’${ACC_NUM}’/${ACC_NUM}/g -e s/’${LOG}’/${LOG}/g >> ${OUTPUT_FILE}

    i=$((i+1))
    done

    3) input.txt (data file)

    ACC1;LOG1;
    ACC2;LOG2;
    ACC3;LOG3;

     

    You may change the files above depending on your requirements. Cheers. 🙂

     



    UNIX – Shell script to capture SQL query using Oracle sqlplus

    Posted on April 22nd, 2012 by fath

    Hi All,
    In my project, as part of Performance Testing team, I’ve wrote a number of scripts to help us perform our duty in system tunings. Here. I’d like to share one of my shell script that can help to capture SQL query running in the background.Feel free to modify this script to fit your own requirement.

     

    ###############################
    # CAPTURE SQL – by Fath #
    ###############################
    ################# PARAMETERS #################

    ##############################################
    #SH_LOG=”$location/CAPTURE_SQL.log”

    clear
    echo “*****************************************************************”
    echo “PV SQL CAPTURE SCRIPT”
    echo “*****************************************************************”

    echo “LOADING CAPTURING SQL..”

    echo “”
    pros=`ps -ef | grep ora_pmon | awk ‘{print $9}’ | grep ora_pmon_ | awk ‘{print substr($1,10)}’`

    echo “Database running on Oracle Process = $pros”
    echo “Oracle SID = $ORACLE_SID”
    echo “Proceed? [y/n]”
    read option
    echo “”

    if [ “$option” = “y” ]
    then
    echo “Enter sid and serial#”
    echo “SID:”
    read sid
    echo “Serial #:”
    read serial

    result=`sqlplus -s ‘/as sysdba’ << ENDOFSQL
    begin
    dbms_system.set_ev(‘$sid’,’$serial’,10046,12,”);
    end;
    /

    begin
    DBMS_SYSTEM.SET_SQL_TRACE_IN_SESSION (sid=>’$sid’, serial#=>’$serial’,sql_trace=>TRUE);
    end;
    /
    show parameter user_dump_dest
    exit;
    ENDOFSQL`

    #path=”$result”

    echo “”
    echo “——————————-”
    echo “Remarks:”
    echo “Spooled queries will be generated in:”
    #echo “$path” | grep /app | awk ‘{print $3}’

    path=”/app/oracle/admin/NSBLPVT/udump”
    echo “$path”
    echo “——————————-”
    echo “”

    while true
    do
    echo “Stop capturing? [y/n]”
    read option2
    echo “”

    if [ “$option2” = “y” ]
    then
    result2=`sqlplus -s ‘/as sysdba’ << ENDOFSQL
    begin
    DBMS_SYSTEM.SET_SQL_TRACE_IN_SESSION (sid=>’$sid’, serial#=>’$serial’,sql_trace=>FALSE);
    end;
    /
    exit;
    ENDOFSQL`

    echo “——————————-”
    echo “Results: ”
    echo “SQL captured in: ”
    result3=`ls -lrt $path | tail -n 1 | awk ‘{print $9}’`
    echo “$result3”
    echo “Converting trace file to log…”
    result4=`tkprof $path/$result3 SQL_CAPTURED[$result3].log sys=no waits=yes sort=exeela`
    echo “Converted to SQL_CAPTURED[$result3].log…”
    echo “Completed.”
    echo “——————————-”

    break
    fi
    done
    fi

    echo “”
    echo “SEE YOU AGAIN!!”
    echo “”