gowf67 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks. Trying to flatten the output of the Windows "qwinsta" command to produce a "user=Active,user2=Disc,user3=Disc" single line output for Nagios. I'm having trouble deciding which type of field processing behavior to use:

while (<>) { chomp; # strip record separator @Fld = split(' ', $_, -1); if ($awk) { print $Fld[2] . '=' . $Fld[4]; }
is not quite working for me. Thanks!

Replies are listed 'Best First'.
Re: flatten record data
by toolic (Bishop) on Sep 09, 2011 at 16:33 UTC
    I had never heard of qwinsta before, but when I run it, it looks like it outputs its data in fixed-width fields. If that is the case, consider using unpack instead of split.
    is not quite working for me
    Please describe how. Show the exact qwinsta output you get, inside code tags (Writeup Formatting Tips).
Re: flatten record data
by davido (Cardinal) on Sep 09, 2011 at 16:34 UTC

    For the benefit of those who don't have or know about the "qwinsta" command, perhaps you could provide an example of its output, which is being used as input to your script.

    I assume the "user=Active,....." stuff is the output you would like to produce, right?

    Next, you state, "is not quote working for me." We are programmers here, and we are not afraid of specifics. Please provide us with a description of the output you are getting and how it fails to meet your needs.

    The way your question is posted we cannot answer properly. We do enjoy helping, and at least for me, asking a few more questions is the best help I can provide to your question. Once you answer them, either I or someone else will probably be able to do a better job of responding directly to your question.


    Dave

Re: flatten record data
by hbm (Hermit) on Sep 09, 2011 at 16:55 UTC

    I just threw this together, mostly because I wanted to try qwinsta. It does what you seem to want on my system.

    qwinsta.exe |perl -ne "push @who, qq{$1=$2} if /^.{19}(\S+)\s+\d+\s+(\ +S+)/; END {print join',',@who}"
      Thanks! I knew there should be a one-liner for this but struggled to figure it out. Thank you also to the others that replied, I will try to be more specific next time. My apologies. Perl is the BEST!