我需要wsadmin.sh脚本以及jython的帮助。 我正在创建一个脚本,以通过wsadmin.sh为用户提供控制台访问权限 如果我在consoleacces.py文件中对用户名详细信息进行硬编码,我可以使其工作,但是我的要求是在运行时提供用户名详细信息,以便我可以针对不同的用户多次使用该脚本。>
工作中:
wsadmin.sh -lang jython -f /tmp/consoleaccess.py
consoleaccess.py的内容
AdminTask.mapUsersToAdminRole('[-accessids [user:defaultWIMFileBasedRealm/employeenumber=123,ou=people,ou=country,o=office] -roleName administrator -userids user1]')
AdminConfig.save()
agBean=AdminControl.queryNames('type=AuthorizationGroupManager,process=dmgr,*');null=AdminControl.invoke(agBean, 'refreshAll')
不起作用
wsadmin.sh -lang jython -f /tmp/consoleaccess.py 123 user1 administrator
consoleaccess.py的内容
import sys
AdminTask.mapUsersToAdminRole('[-accessids [user:defaultWIMFileBasedRealm/employeenumber=sys.argv[1],ou=people,ou=americas,o=SIAM_ED] -roleName sys.argv[3] -userids sys.argv[2]]')
AdminConfig.save()
agBean=AdminControl.queryNames('type=AuthorizationGroupManager,process=dmgr,*');null=AdminControl.invoke(agBean, 'refreshAll')
错误:
WASX7209I: Connected to process "dmgr" on node host1 using SOAP connector; The type of process is: DeploymentManager
WASX7303I: The following options are passed to the scripting environment and are available as arguments that are stored in the argv variable: "[123, user1, administrator]"
WASX7017E: Exception received while running file "/tmp/consoleaccess.py"; exception information: com.ibm.ws.scripting.ScriptingException: WASX8009E: Invalid parameter: [-accessids [user:defaultWIMFileBasedRealm/employeenumber=sys.argv[1],ou=people,ou=americas,o=SIAM_ED] -roleName sys.argv[3] -userids sys.argv[2]]
答案 0 :(得分:0)
--
将标志与参数分开怎么办?
wsadmin.sh -lang jython -f /tmp/consoleaccess.py -- 123 user1 administrator
并将sys.argv移出字符串:
'...employeenumber=' + sys.argv[1] + ',ou=people,ou=americas,o=SIAM_ED] -roleName ' + sys.argv[3] + ' -userids ' + sys.argv[2]])
答案 1 :(得分:0)
如下更新脚本。
注意:在wsadmin Jython中,程序或脚本的名称不是sys.argv的一部分。因此,您的第一个参数是 sys.argv [0] 而不是 sys.argv [1]
import sys
userEmpNo=sys.argv[0]
userName=sys.argv[1]
userRole=sys.argv[2]
AdminTask.mapUsersToAdminRole('[-accessids [user:defaultWIMFileBasedRealm/employeenumber=' +userEmpNo+ ',ou=people,ou=americas,o=SIAM_ED] -roleName ' +userRole+ ' -userids ' +userName+ ']')
AdminConfig.save()
agBean=AdminControl.queryNames('type=AuthorizationGroupManager,process=dmgr,*');null=AdminControl.invoke(agBean, 'refreshAll')
并以
运行脚本wsadmin.sh -lang jython -f /tmp/consoleaccess.py 123 user1 administrator