Results 1 to 4 of 4

Thread: newbie hurtin'

  1. #1
    Join Date
    Sep 2003
    Posts
    13

    Unanswered: newbie hurtin'

    I would like a little help if possible.

    I need to write a shell script that will query a DB to get a list of processes. I then need to check how many instances of each process are running. I can get the data from the DB and check how many processes. However, how would I enter the list of processes received from the DB query into a loop to check how many instances are running and exit when all the processes have been checked?

    Should I send the query output to another file and then use awk to read it back into a variable one record at a time and run it through a loop?

    How?

    Any help would be greatly appreciated.

    If what I wrote is confusing, let me know and I will clarify...if I can.

  2. #2
    Join Date
    Sep 2003
    Posts
    13
    Sorry I forgot. The data from the query is a typical output from a Sybase query:

    Processes
    ------------
    PROC1
    PROC2
    PROC3
    PROC4
    PROC5

    (5 rows affected)

    The number of processes can change daily.

    Again thanks.

  3. #3
    Join Date
    Sep 2003
    Posts
    13
    Hello?

    ANy help would be appreciated due to people dumping major tasks upon my dear little head.

    I'm not asking you to right the thing, just kind of give me a framework that you would use.

  4. #4
    Join Date
    Sep 2003
    Posts
    13
    ok, ok, ok, i get it. you all hate me. just joking.

    how about this, can you guys look over my code and tell me if there is a better way to do it. i have it working, but i want to learn if there are better ways of doing what it does, ie simpler, as well as hone my abilities? it runs as a cronjob and the output is appended to a file in /tmp.

    thanks for any help.

    #!/usr/bin/ksh
    ##
    ## JWD 10/30/03
    ##
    ##

    #### Setting Array for While Loop
    ####
    set -A PROC `$ISQL << !
    use config_db
    go
    select distinct PROCESS_NAME from PROCESSES
    where BLOCK = 'n'
    go
    !`

    #### Setting variable to count number of processes for loop
    #### used for loop control
    COUNT1=`$ISQL << !
    use config_db
    go
    select distinct PROCESS_NAME from PROCESSES
    where BLOCK = 'n'
    go
    !`
    LOOP_NUM=$(( `echo $COUNT1 | awk '{print NF}` - 3 ))

    #### Counting total number of processes
    #### that should be running
    COUNTALL_NORM=`$ISQL << !
    use config_db
    go
    select count(PROCESS_NAME) from PROCESSES
    where BLOCK = 'n'
    go
    !`

    #### Comparing the total number of actual processes
    #### to the number that should be running
    function total_proc {
    COUNTALL_ACT=`/usr/bin/ps -ef -o comm | grep netrac | wc -l`
    echo $COUNTALL_ACT processes currently running.
    CC=`echo $COUNTALL_NORM | awk '{ print $2 }`
    echo
    COUNTALL_DIFF=$(( $COUNTALL_ACT - $CC ))
    if [ $COUNTALL_ACT -gt $CC ];
    then
    echo There are $COUNTALL_DIFF too many processes currently running.
    echo;
    fi
    }

    #### Comparing the number of individual processes
    #### to the number that should be running
    function proc_check {
    COUNTIND_NORM=`$ISQL << !
    use config_db
    go
    select count(PROCESS_NAME) from PROCESSES
    where BLOCK = 'n' and PROCESS_NAME = '$PNAME'
    go
    !`
    COUNTIND_ACT=`/usr/bin/ps -ef -o comm | grep netrac | grep $PNAME | wc -l`
    COUNTIND_NORMA=`echo $COUNTIND_NORM | awk '{ print $2 }`
    COUNTIND_DIFF=$(( $COUNTIND_ACT - $COUNTIND_NORMA ))
    if [ $COUNTIND_ACT -gt $COUNTIND_NORMA ];
    then
    echo There are $COUNTIND_DIFF too many $PNAME processes currently running.
    echo;
    fi
    }

    /usr/bin/date
    echo
    total_proc
    X=2
    while (( $X < $LOOP_NUM ))
    do
    PNAME=${PROC[$X]}
    proc_check
    X=$(( $X + 1 ))
    done

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •