AS400 scan all files / libraries for string

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?
cosmitAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dude02Commented:
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.
0
cosmitAuthor Commented:
Thanks for the great reference material dude02.  Unfortunately, it did not help my current situation.  It is great material though.
0
dude02Commented:
You can use FNDSTRPDM command to search out strings.

I hope this helps.
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

cosmitAuthor 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?
0
Gary PattersonVP 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
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cosmitAuthor Commented:
Once again you came through -- Thanks!!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Operating Systems

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.