How to sort NSH Script Job output properly for a non-runscript NSH Script

Version 1
    Share:|

    If you set up an NSH Script in the Configuration Manager to run centrally (on the application server) and take %h or %f as an argument, you'll find that all output-- regardless of the server to which it belongs-- gets collected under the root of the job log.  This makes for messy job logs.  An example script:

     

    ********************************************

     

    HOSTLIST=`cat "$1`

     

    foreach host in "$HOSTLIST"

    do

        echo "Doing something to this server."

    done

     

    ********************************************

     

    The way that the runscript-based NSH Scripts categorize the output by host is by pulling the hostname off the output lines, since when you run a "runcmd" or "runscript", each output line is prepended with the hostname.

     

    winagent%

    winagent% runcmd -NH -V -h seams250 -e ls /temp

    (winagent) test-results.csv

    (winagent) test-results.html

    (winagent) test_status.nsh

    (winagent) user_info.dat

    (winagent) Exit Code 0

    winagent%

     

    What I did is modify my %f/%h scripts to prepend ($host) to all output lines.  This way, all job output is grouped into the proper host.  This makes for much cleaner jobs.  See modified loop below:

     

    ********************************************

     

    HOSTLIST=`cat "$1`

     

    foreach host in "$HOSTLIST"

    do

        echo "($host) Doing something to this server."

    done

     

    ********************************************

     

    I suggest you try it sometime.