Feb 22 2016

AS400 Mass Object Owner Change

Published by at 2:43 pm under AS400




Common Ways

There are many ways to change an object owner such as CHGOBJOWN for a single object or WRKOBJOWN then press 9 for each object if you want to start with all objects belonging to somebody.
What if you have thousands?
 
Like many sites like itjungle report,
CHGOWN OBJ(‘/qsys.lib/mylib.lib/*.*’) NEWOWN(new_owner) RVKOLDAUT(*YES)
is a good way to change the owner of all objects within the same library.
 
But there is more powerful if you’re not against using QSHELL or PASE (run QSH or CALL QP2TERM).
 

QSH/PASE

You can move into the library’s directory with cd. Always append .LIB to your library

cd /QSYS.LIB/MYLIB.LIB

 
You can easily count the number of objects:

$ ls -1 | wc -l
    6228

 
Display all objects owner with ls and more to display one page at a time (can be slow if loads of objects)

$ ls -l | more
total 190672
drwx---rwx    2 owner    0             28672 Jan  5 10:37 $BUL100.FILE
drwx---rwx    2 owner    0             20480 Jan  5 10:37 $BUL200.FILE
...

 
Change owner for all objects is as easy as:

chown new_owner *.*

You can also be more specific with *.FILE or MY_*.PRG.
 
And this is where it gets interesting. You can change all objects that have no owner

find . -nouser | xargs chown newowner

Use with care, read on…
 
You can also change all objects belonging to somebody in particular

find . -user oldowner | xargs chown new owner

These commands can save you a lot of time!
 

A Few Things You Should Know

find will also search in subdirectories.
 
You may get an unknown username error:

$ chown lgusername AABL01WC.PGM
chown: lgusername is an unknown username.

You need to get the user id in his profile and use that number instead, if the username length is greater than 8 characters:

$ chown 1073 AABL01WC.PGM

See that note from IBM. You’re better off setting all usernames with 8 characters or less in iSeries.
 
Knowing the username length problem, the command “find . -nouser” will also return files/objects belonging to 9 or 10 character long profiles! Shame IBM didn’t set the username max length to 10 as well in PASE.
 
One last piece of advice: connect via SSH for a bigger terminal window.


No responses yet

Trackback URI | Comments RSS

Leave a Reply