Solved

script to create websphere admin users

Posted on 2010-08-31
22
4,198 Views
Last Modified: 2013-12-11
i want to write a script to add admin users to websphere. Is it possible to write in jython ? or perl is easier . Any pointers how to go about

Thanks !
0
Comment
Question by:wasadmin11
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 10
22 Comments
 
LVL 41

Expert Comment

by:HonorGod
ID: 33568571
What authentication is being used?

Generally, users are associated with roles (e.g., Administrator).
Is this what you're trying to do?
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 33568596
0
 
LVL 2

Author Comment

by:wasadmin11
ID: 33576358
Authentication is federated repositories

A script to add a number of users with roles (admins)
0
Don't miss ATEN at NAB Show April 24-27!

Visit ATEN at NAB Show to learn how our "Seamlessly Entertaining" solutions deliver fast, precise video streaming without delays for the broadcasting and media environment. ATEN will showcase its 16x16 Modular Matrix Switch (VM1600) and KVM Over IP Solution (KE6900 series).

 
LVL 41

Expert Comment

by:HonorGod
ID: 33577134
Chapter 12 of this book appears to have what you need:

http://www.ibmpressbooks.com/bookstore/product.asp?isbn=0137009526

Some sample scripts are available from that site:
- click "Downloads"
- Save the "Sample Scripts" zip file
- Look for the script related to chapter 12
0
 
LVL 2

Author Comment

by:wasadmin11
ID: 33585977
Thanks for the info. Is it possible to run a jython script inside a shell script
Psuedo code is below: Basically i will read the user names , passwords from a txt file. I dont know how to map the user name to a role (like Administrator)

#!/usr/bin/ksh

NEW_USERS="/path/to/Usernames_file"
 
cat ${NEW_USERS} | \
while read USER PASSWORD
do
`wsadmin -lang jython -c "$AdminTask.createUser {-uid $USER –password PASSWORD -confirmPassword PASSWORD }"`

done
AdminConfig.save()
Sync1 = AdminControl.completeObjectName('type=NodeSync,node=myNodeName,*')
AdminControl.invoke(Sync1, 'sync')
0
 
LVL 41

Accepted Solution

by:
HonorGod earned 500 total points
ID: 33586156
> Is it possible to run a jython script inside a shell script

Sure.

Note: The AdminConfig.save() is not necessary.  When you use:

wsadmin.sh -c command

isn't required.

http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=/com.ibm.websphere.nd.doc/info/ae/ae/rxml_commandline.html

"If you invoke the wsadmin tool with the -c option, any changes that you make to the configuration are saved automatically"

Also, each call to wsadmin.sh would need to start a new JVM, so it would be better to "write" a script with your shell script, and then pass this to wsadmin...

Does this make sense?
0
 
LVL 2

Author Comment

by:wasadmin11
ID: 33609652
I have written something like this.

1) How do i map a role like Administrator /Operator to a user/group . Am not seeing any command/method

2) For synching the node . IHow do i get the nodeName ?


Sync1 = AdminControl.completeObjectName('type=NodeSync,node=myNodeName,*')
AdminControl.invoke(Sync1, 'sync')







#!/usr/bin/ksh

# To create WAS users and groups
NEW_USERS="/path/to/users_file"

E_FILE_ACCESS=1
E_ZERO_SIZE=2

if [ ! -r "$1" ]     # Is specified input file readable?

then
  echo "Can't read from input file!"
  echo "Usage: $0 provide user list file name"
  exit $E_FILE_ACCESS


fi                    

if [ -z "$1" ]  # is file zero size ?
then
  echo "Need to specify output file."
  echo "Usage: $0 provide the list of names, groups, password in the file "
  exit $E_WRONG_ARGS
fi

wasadmin.sh -f "createusers.py"


createusers.py




###### To create users  #############

AdminTask.createUser('-uid DCBROWN -password xxxxxxxx -confirmPassword xxxxxxxx -cn DCBROWN -sn DCBROWN')
AdminTask.createUser('-uid DNARMSTRONG -password xxxxxxxx -confirmPassword xxxxxxxx -cn DNARMSTRONG -sn DNARMSTRONG')
AdminTask.createUser('-uid DGADAMS -password xxxxxxx -confirmPassword xxxxxxxx -cn DGADAMS -sn DADAMS')


################To add members to the groups###############################33
AdminTask.addMemberToGroup('-memberUniqueName uid=DCBROWN,o=defaultWIMFileBasedRealm -groupUniqueNamecn=DUSERS,o=defaultWIMFileBasedRealm')
 
AdminTask.addMemberToGroup('-memberUniqueName uid=DNARMSTRONG,o=defaultWIMFileBasedRealm -groupUniqueName cn=DUSERS,o=defaultWIMFileBasedRealm')


AdminTask.addMemberToGroup('-memberUniqueName uid=DNARMSTRONG,o=defaultWIMFileBasedRealm -groupUniqueName cn=DMANAGERS,o=defaultWIMFileBasedRealm')




###### To add bulk users from a file ################

cat ${NEW_USERS} | \
while read USER PASSWORD GROUP
do
AdminTask.createUser('[-uid USER -password PASSWORD -confirmPassword PASSWORD]')
AdminTask.addMemberToGroup('-memberUniqueName uid=USER,o=defaultWIMFileBasedRealm -groupUniqueName cn=USER,o=defaultWIMFileBasedRealm')
done

 

### #####To  create groups##############################
AdminTask.createGroup('-cn users')
AdminTask.createGroup('-cn admins')
################################################

0
 
LVL 2

Author Comment

by:wasadmin11
ID: 33626421
i wrote the script in python ( this is my first python script, please bear with me) but am getting ImportError : no module named csv.
Any idea ?

 

import csv
namelist= csv.reader(open('username.csv', 'rb'))

for userid,password,firstname,lastname,groupname,role in namelist:
   
    print '%s, %s, %s, %s, %s, %s'  %(userid, password, firstname, lastname,groupname,role)
    AdminTask.createUser('-uid userid -password password -confirmPassword password -cn firstname -sn lastname')
    AdminTask.addMemberToGroup('-memberUniqueName uid=username,o=defaultWIMFileBasedRealm -groupUniqueNamecn=Admins,o=defaultWIMFileBasedRealm')
    AdminTask.mapUsersToAdminRole('[-roleName role -userids userid]')
    

Open in new window

0
 
LVL 2

Author Comment

by:wasadmin11
ID: 33626777
i am using python 27 on windows . In the python shell i can import
>>> import csv
>>> dir (csv)
['Dialect', 'DictReader', 'DictWriter', 'Error', 'QUOTE_ALL', 'QUOTE_MINIMAL', 'QUOTE_NONE', 'QUOTE_NONNUMERIC', 'Sniffer', 'StringIO', '_Dialect', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__version__', 'excel', 'excel_tab', 'field_size_limit', 'get_dialect', 'list_dialects', 're', 'reader', 'reduce', 'register_dialect', 'unregister_dialect', 'writer']

but throws error when i run it with wsadmin.bat -f "createusers.py"
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 33627232
Ah, remember that wsadmin isn't the same as Python.

wsadmin, when the "-lang jython" parameter is specified, is using a version of Jython, which is a Java implementation of the Python programing language.

It isn't the latest version of Python.  It is, in fact, version 2.1 of Jython (which isn't even the latest and greatest version of Jython :-( ).  And only includes a subset of the available Python modules.

What error is thrown when you execute:


wsadmin -f createusers.py

Open in new window

0
 
LVL 41

Expert Comment

by:HonorGod
ID: 33627283
So the error is?

no module named csv.

That's because the libraries that are available to Python aren't the same as the ones available to Jython.

If you execute wsadmin without parameters (or even specify "-conntype none" to get an unconnected, or local mode interactive session), you'll see that csv isn't one of the available libraries/modules
[root@ragdoll bin]# ./wsadmin.sh -conntype none -profileName AppSrv00 -lang jython
WASX7357I: By request, this scripting client is not connected to any server process. Certain configuration and application operations will be available in local mode.
WASX7031I: For help, enter: "print Help.help()"
wsadmin>import csv
WASX7015E: Exception running command: "import csv"; exception information:
 com.ibm.bsf.BSFException: exception from Jython:
Traceback (innermost last):
  File "<input>", line 1, in ?
ImportError: no module named csv

wsadmin>

Open in new window

0
 
LVL 2

Author Comment

by:wasadmin11
ID: 33636918
HonorGod,

can you please help me with the code required  ., i am still learning jython  
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 33639874
I can try. ;-)

Looking into the csv module to see what it does, and how...
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 33640368
Can you provide a sample (CSV) input file for me to use?
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 33640384
I tried using a copy of csv.py from a Jython build, but ran into problems. :-(

So, I'm willing to write some code to read / process a CSV into a list of tuples or something.
That might be suitable for you.
0
 
LVL 2

Author Comment

by:wasadmin11
ID: 33644263
thanks a lot !. attached is a sample csv file. Basically i want add all the users and map their roles to their ids
username.csv
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 33647933
What version of WebSphere are you using?

execute:

/opt/IBM/WebSphere/AppServer/bin/versionInfo.sh

and look for the section entitled "Installed Product"
0
 
LVL 2

Author Comment

by:wasadmin11
ID: 33660012
its 6.1.0.27
0
 
LVL 2

Author Comment

by:wasadmin11
ID: 33670161
I have been able to write the script :-). I wanted to add the member to the group but am not able to pass the parameters

this is the command line which works, but unable to get it working inside the script

AdminTask.addMemberToGroup('-memberUniqueName uid=DCBROWN,o=defaultWIMFileBasedRealm -groupUniqueName cn=DUSERS,o=defaultWIMFileBasedRealm')

any ideas ?. I want to know in general how to pass parameters/variables to AdminTask or any other wsadmin command.
0
 
LVL 2

Author Comment

by:wasadmin11
ID: 33670177
think the script did not get posted ..pasting it below

import sys

filename = "C:\\Documents and Settings\\Administrator\\AST\\workspace\\AdminScriptingProject\\Scripts\\username.txt"
print filename
global AdminConfig
global AdminTask

#filename = sys.argv[ 0 ]
print 'Processing: ' + filename
f = open( filename )
data = f.read()
for lines in data.splitlines():
          print '>>>', lines
          info = lines.split( ',' )
          print info[0],info[1],info[2],info[3],info[4],info[5],info[6]
          AdminTask.createUser( ['-uid',info[0],'-password', info[1],'-confirmPassword', info[1],'-mail',info[2],'-cn',info[3],'-sn',info[4]])
          AdminTask.mapUsersToAdminRole( ['-roleName', info [6], '-userids', info[ 0 ] ] )
f.close()
print 'Finished processing usernames'
AdminConfig.save()
print 'Completed saving the configuration'
 
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 33713340
Thanks for the grade & points

Good luck & have a great day.
0
 

Expert Comment

by:crazywolf2010
ID: 34710691
Hi,
I am using this script under RHEL WAS 6.x and I have following error.

Can someone please help?

[was61@tmp]$ /opt/IBM/WebSphere/AppServer/bin/wsadmin.sh -conntype none  -lang jython -f  /tmp/create_user.py
WASX7357I: By request, this scripting client is not connected to any server process. Certain configuration and application operations will be available in local mode.
/tmp/username.txt
Processing: /tmp/username.txt
>>> userid,password,email,last name,first name,role
userid password email lastname firstname roleWASX7017E: Exception received while running file "/tmp/create_user.py"; exception information: com.ibm.bsf.BSFException: exception from Jython:
Traceback (innermost last):
  File "<string>", line 15, in ?
IndexError: index out of range: 6

Username.text contains

userid,password,email,last name,first name,role
test,password,test@test.com,tester,tester,administrator

many thanks
0

Featured Post

Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Shell Mail is not working 5 124
Powershell Command to create a csv file using UTF-8 encoding 3 262
Run same command on multiple files in Linux 3 76
while read ID; do 4 58
Verbose logging is used to diagnose garbage collector problems. By default, -verbose:gc output is written to either native_stderr.log or native_stdout.log.   It is also possible to redirect the logs to a user-specified file. This article will de…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question