AS400 scan all files / libraries for string

cosmit
cosmit used Ask the Experts™
on
In preparation for a softare upgrade, I need to search all files / libraries on my AS400 for a certain string.  This string could be contained in CL and / or RPG programs.  I used STRPDM  to scan and I got some results however, I could not scan the entire AS/400 as I need to (unless I am using the utility incorrectly?!)  I had to qualify a file and library before it could scan.  What is the best way to determine every instance where this string is found?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
This is a great website that I keep on hand just in case I have to find something on my iSeries.

http://krypton.mnsu.edu/~j3gum/web/as400/intref.html

I hope this helps.

Author

Commented:
Thanks for the great reference material dude02.  Unfortunately, it did not help my current situation.  It is great material though.

Commented:
You can use FNDSTRPDM command to search out strings.

I hope this helps.
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

Author

Commented:
I tried the FNDSTRPDM command but it requires you to specify a file and a library list.  I want to search ALL files in ALL libraries so this won't do the trick.

Any other suggestions?
VP Technology / Senior Consultant
Commented:
This is a bit tricky if you aren't used to Unix-style commands on the AS/400, but you can use the Qshell commands to do what you want.  Note that this requires that you have Qshell installed.  It is a free, optionally-installable component of the operating system.  Just type "QSH" at the command line to see if it is installed.  If it isn't, ask your sysadmin to install it for you.

First, dump a list of all physical files in the system to an outfile.  You may not see files that you don't hae rights to, so you probably want to run this whole process under a profile with *ALLOBJ authority.  

Note that this outfile will contain all data files and all source files in the system.

DSPFD *ALL/*ALL *PF OUTFILE(mylib/allfiles)
Then execute a Qshell command string similar to the following.  This can take a LONG time to run, depending on the number of members being searched, and you should probably run it in batch.  

There are several ways to start a Qshell command:

1) Interactively enter 'QSH" and press enter for a terminal-session style interactive session.
2) Prompt the QSH command and enter the Qshell command string in the paramater provided.  This enables you to run Qshell commands from CL, for example.
3) Use SBMJOB to execute the QSH command, containing a Qshell command string, in batch.

db2 "SELECT '/QSYS.LIB/' || trim(MBLIB) || '.LIB/' || trim(MBFILE) || '.FILE/' || trim(MBNAME) || '.MBR' FROM mylib.allfiles WHERE mbseu2='CLP'" | xargs grep '172.' > /grep.txt  

1) The "db2" command runs an SQL query over the "allfiles" table you created above, and creates a list of source members to search in IFS format (//QSYS.LIB/somelib.LIB/file.FILE/member.MBR).  This example just selects members with the Source Attribute set to CLP.  If you want to search other members, you will need to modify the query a bit.  Instead of listing all of the possible source member types, there is a file attribute that indicates if the file is a Data file or a Source file.  You could just use that in place of the mbseu2 clause.  I'm not on the corporate network right now so I can't get you the field name, but if you look at the fields in the "allfiles" file, you should see it.

2) The "|" (pipe) symbol redirects this list of members into the "xargs" command.  Xargs allows you to take a list that is generated in one command and pass it to another command that cannot accept an arbitrarily-long list of parameters.

3) "grep" searches each member for the given string, and the ">" symbol redirects the list of members where the string "172." is found to a file called "grep.txt" in the root of the IFS.

Note that grep can take a regular expression, and has lots of options, so the search can be extremely complex.  Grep is a common Linux and Unix command, and you can find examples of search syntax at thousands of sites.  Search for "grep", "grep tutorial", and "regular expressions".

You can find more information on the IBM Qshell environament and related Qshell commands at:

http://publib.boulder.ibm.com/infocenter/iseries/v5r3/index.jsp?topic=/rzahz/intro.htm

- Gary Patterson

Author

Commented:
Once again you came through -- Thanks!!!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial