Sponsored Links
Sponsored Link

sponsored links

Collapse

Announcement

Collapse
No announcement yet.

Refinement of Spool File Search Qshell

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Refinement of Spool File Search Qshell

    Hi All

    Through no skill of my own, I've managed to cobble together some Qshell code to search spool files with a particular file name, e.g.:

    Code:
    system 'WRKSPLF SELECT(usrname *ALL *ALL *ALL *ALL spoolfilename) PERIOD((*AVAIL *CURRENT))'                             
    | grep -i spoolfilename                                                                                                
    | awk '{print "system -i \"qsh cmd('\''catsplf -j "$14"/"$2"/"$13" "$1" "$12"|grep '\'\''mysearchstring'\'\''    '\'')\" "}'
    | sh
    This works fine, but still has a couple of inadequacies:

    1. It sends a failure line for every spool file that doesn't have a match, thus scrolling a lot and separating the positive results from each other

    but more importantly:

    2. It doesn't actually identify which spool file the displayed string was found in.

    I got most of the code from here.

    So I would like to know if the job/spool/number can be prependent or appended to the output and if the error messages can be suppressed.

    One day I'll learn Qshell from the ground up but for now I need every moment to do paid projects.

  • #2
    Hi William...

    this is a sequence of commands with the output from each command sent as input to the next command. That's what the | character does, it sends the output from one command to the next.

    So it does these steps:

    1) Run the system's WRKSPLF command to get a list of spooled files for a given username and spooled file name, starting with the *CURRENT date. The output is the same as it would be if you used the same WRKSPLF command with OUTPUT(*PRINT), except the output goes to the next command instead of the spool.

    2) The output of WRKSPLF (the list of spooled files) is sent to "grep", which is just a search tool. it is searching for the selected spooled file name in order to strip the headings off of the WRKSPLF output... so that you only have the data rows of the report.

    3) awk is used to split the data rows into fields. If you ran the above WRKSPLF command with OUTPUT(*PRINT) you'd see that it lists a bunch of columns for each spooled file selected. The 14th column contains the job number, the 2nd column contains the user name, and the 13th column contains the job name. So when awk does $14/$2/$13 this gives you the job number. It is using this to construct a string that happens to contain another command.

    4) The list of commands output from step 3 is sent to "sh" when runs them. In this case, it's using the QShell "catsplf" command to display the contents of a spooled file, and sending that output to "grep" to display matching records.

    Personally, I would've been more likely to do this from a CL or RPG command rather than QShell. I guess it was done in QShell because it's fewer lines of code? But, since the code isn't particularly easy to follow (and since you aren't comfortable with coding Unix shell scripts) it seems to me that it's not worth saving a few lines of code.

    If you wanted to print the spooled file name, you could simply add an "echo" statement that prints the same fields that you're passing to "catsplf". Though, this only makes the code harder to follow, imho... since it's lumping more stuff into one command line... (untested, but should work)

    Code:
    system 'WRKSPLF SELECT(usrname *ALL *ALL *ALL *ALL spoolfilename) PERIOD((*AVAIL *CURRENT))'                             
    | grep -i spoolfilename                                                                                                
    | awk '{print "echo "$14"/"$2"/"$13" "$1" "$12"; system -i \"qsh cmd('\''catsplf -j "$14"/"$2"/"$13" "$1" "$12"|grep '\'\''mysearchstring'\'\''    '\'')\" "}'
    | sh
    At what point do you say "this is too hard to read/maintain"?

    Comment


    • #3
      Thanks. That's very interesting and works perfectly.

      In this particular case maintenance is not an issue as it's just a "cut'n'paste" into interactive qshell that I can do at any client off the cuff without writing a program at all. I don't always have permission to create new objects as I wish, or to load ones I've done elsewhere, so interactive SQL/qshell can be lifesaver.

      60% of the time, if I want to know if/how/why something's on spool file I'd just check the IBM i files and/or program.
      39% of the time I'd just browse the spool files one at a time if there weren't too many.

      So this is just a Handy Dandy cheat for the 1% of the time when there are dozens of spool files and it's too hard to figure out which file(s) or what code produces the output I'm looking for. Or maybe if I needed to find and manipulate the spool file itself (delete it/move it to a queue that emails it, etc.)

      Comment


      • #4
        p.s. For those playing along at home, I have a partial answer to the problem of verbose output.

        To stop the exit status messages, just change the last line from

        | sh

        to

        | sh 2>/dev/null

        Comment


        • #5
          not sure if this is something you would be interested in but i got tired of futzing around with WRKSPLF years ago and rolled my own (WRKSPL(saved at v6.1 btw). i'm attaching it here since my website is currently down(has been for a while) just not in the mood to mess with it. anywho, there's several functions in it that i think are really beneficial (i.e. repeat option(a la PDM), sort by any column(a la WRKACTJOB, etc)) it does support generics in some of the parameters. the biggest shortcoming(i haven't taken the small amount of time to fix) is that for an outq you have to specify the outq library as *LIBL, etc are not supported(at the time it was written the API didn't support *LIBL not sure if it does now or not). since i have been pretty much relegated to M$ hell known as SQL Server i haven't had the time to work on anything. i'm doing extreme OJT on M$ wrkspl.savf

          Attached Files
          I'm not anti-social, I just don't like people -Tommy Holden

          Comment


          • WilliamTasker
            WilliamTasker commented
            Editing a comment
            Great, thanks. I'll have a look.

        sponsored links

        Collapse

        Working...
        X