Automic Workload Automation

 View Only

Bash functions to identify AE server processes

  • 1.  Bash functions to identify AE server processes

    Posted Feb 28, 2024 03:31 AM
    Edited by Michael A. Lowry Mar 20, 2024 10:08 AM

    Here are some Bash functions that can be used to quickly identify AE server processes by type and role.

    Identification of process types and roles relies parsing recent logs and looking for particular messages.

    • PWP: identified by finding the most recent U00003475 message in any WP log.
    • DWP: distinguished from ordinary WP by reading the most recent U00003389 message in the WP log.
    • ORP & RWP: identified by finding the most recent corresponding U00003344 message in any WP log.
    • REST Process & JCP: identified by finding the most recent corresponding U00003400 JCP message in any CP log.
    • JWP: identified by finding the most recent corresponding U00003400 JWP message in anw WP log.
    • JWP roles (AUT, IDX, PER, and UTL): identified finding the most recent U00045395 message in any JWP log.
    • CP: identified by finding CP logs that lack a U00003400 JCP message.
    • WP: identified by finding WP logs that lack a U00003400 JWP message.
    UC4_Log_Dir="/var/uc4/server"
    pwpname () {
    PWP_Process_Name=$(find ${UC4_Log_Dir} -name WPsrv_\*_log_???_00.txt -mmin -60 -exec grep U00003475 {} \; | sort | tail -1 | cut -d\' -f2)
    echo "${PWP_Process_Name}"
    }
    
    pwp () {
    PWP_Process_Name=$(find ${UC4_Log_Dir} -name WPsrv_\*_log_???_00.txt -mmin -60 -exec grep U00003475 {} \; | sort | tail -1 | cut -d\' -f2)
    PWP_Number=$(echo "${PWP_Process_Name}" | cut -d# -f2 | cut -c3-)
    PWP_Log=$(find ${UC4_Log_Dir} -name WPsrv_*_log_${PWP_Number}_00.txt -mmin -480 | tail -1)
    if [[ ! "${PWP_Log}" == "" ]]; then echo "${PWP_Log}"; fi
    }
    
    owp () {
    #OWP_Log=$(find ${UC4_Log_Dir} -name WPsrv_\*_log_???_00.txt -mmin -360 -exec grep -l "processes roles 'O'" {} \; | tail -1 | cut -d: -f1)
    OWP_Log=$(find ${UC4_Log_Dir} -name WPsrv_\*_log_???_00.txt -mmin -360 -exec grep -l "U00003344 Server .* assumes the role 'O'" {} \; | tail -1 | cut -d: -f1)
    echo "${OWP_Log}"
    }
    
    rwp () {
    #RWP_Log=$(find ${UC4_Log_Dir} -name WPsrv_\*_log_???_00.txt -mmin -360 -exec grep -l "processes roles 'R'" {} \; | tail -1 | cut -d: -f1)
    RWP_Log=$(find ${UC4_Log_Dir} -name WPsrv_\*_log_???_00.txt -mmin -360 -exec grep -l "U00003344 Server .* assumes the role 'R'" {} \; | tail -1 | cut -d: -f1)
    echo "${RWP_Log}"
    }
    
    dwp () {
    if [[ "${WP_Logs}" == "" ]]; then WP_Logs="$(aewp)"; fi
    for wplog in ${WP_Logs}; do
            WP_Name=$(log2proc "${wplog}")
            Final_WP_Mode=$(grep "U00003389 Server" ${wplog} | awk -v wp="$WP_Name" -F"'" '$2 ~ wp {print $6}' | tail -1 )
            if [[ "${Final_WP_Mode}" == "DWP" ]]; then
                    if [[ $(echo "${DWP_Log}" | wc -l) -eq 0 ]]; then
                            DWP_Log="${wplog}\n"
                    else
                            DWP_Log="${DWP_Log}${wplog}\n"
                    fi
            fi
    done
    printf "${DWP_Log}"
    }
    
    restp () {
    REST_Log=$(find ${UC4_Log_Dir} -name CPsrv_\*_log_???_00.txt -mmin -360 -exec grep -l "U00003400 Server 'REST API'" {} \; | sort )
    echo "${REST_Log}"
    }
    
    jcp () {
    JCP_Log=$(find ${UC4_Log_Dir} -name CPsrv_\*_log_???_00.txt -mmin -360 -exec grep -l "U00003400 Server 'JCP'" {} \; | sort )
    echo "${JCP_Log}"
    }
    
    jwp () {
    JWP_Log=$(find ${UC4_Log_Dir} -name WPsrv_\*_log_???_00.txt -mtime -5 -exec grep -l "U00003400 Server 'JWP'" {} \; | sort )
    echo "${JWP_Log}"
    }
    
    aewp () {
    WP_Log=$(find ${UC4_Log_Dir} -name WPsrv_\*_log_???_00.txt -mmin -360 -exec grep -L "U00003400 Server 'JWP'" {} \; | sort )
    echo "${WP_Log}"
    }
    
    aecp () {
    CP_Log=$(find ${UC4_Log_Dir} -name CPsrv_\*_log_???_00.txt -mmin -360 -exec grep -L "U00003400 Server 'JCP'" {} \; | sort )
    echo "${CP_Log}"
    }
    
    jwp-aut () {
    JWP_AUT_Log=$(for log in $(jwp); do grep 'U00045395 Assigned roles: \[.*AUT.*\]' $log /dev/null ; done | sort -t':' -k 2 | tail -1 | cut -d':' -f 1)
    echo "${JWP_AUT_Log}"
    }
    
    jwp-idx () {
    JWP_IDX_Log=$(for log in $(jwp); do grep 'U00045395 Assigned roles: \[.*IDX.*\]' $log /dev/null ; done | sort -t':' -k 2 | tail -1 | cut -d':' -f 1)
    echo "${JWP_IDX_Log}"
    }
    
    jwp-per () {
    JWP_PER_Log=$(for log in $(jwp); do grep 'U00045395 Assigned roles: \[.*PER.*\]' $log /dev/null ; done | sort -t':' -k 2 | tail -1 | cut -d':' -f 1)
    echo "${JWP_PER_Log}"
    }
    
    jwp-utl () {
    JWP_UTL_Log=$(for log in $(jwp); do grep 'U00045395 Assigned roles: \[.*UTL.*\]' $log /dev/null ; done | sort -t':' -k 2 | tail -1 | cut -d':' -f 1)
    echo "${JWP_UTL_Log}"
    }

    Note that the jwp-xxx functions operate on the assumption that only one JWP is assigned to each role. (They identify only the JWP most recently assigned the specified role.) The functions only check for messages in recent logs. They do not confirm that the respective AE processes are actually running.

    Most of these functions list the fully qualified paths of the logs of the respective AE server processes. This makes it possible to combine these functions with other commands, e.g., when searching logs for particular messages.

    Enjoy!