Question Bharath Nunepalli · Apr 3, 2020

Calling Security.Users class in a script

Hi,

Has anyone tried to call Security.Users class (in %SYS namespace) for creating or editing users from a shell script (or any programming language)?

If yes, can you please share your code?

We are trying to automate some stuff and would like to know how this worked for others.

Thanks,

Bharath Nunepalli.

Comments

Stephen Canzano · Apr 3, 2020

I've used the Security.Users class in %SYS as well as Security.Roles.  In both cases the documentation suggests you should use the methods to interact with the data.. ie call the Create, Get, Delete methods found in the corresponding class.

0
Bharath Nunepalli · Apr 3, 2020

I have developed some shell scripts for Caché database maintenance, and they run on AIX.

These scripts just run simple commands like "Status^JOURNAL".

I haven't coded scripts for calling classes or methods. So, just want know whether that's possible in shell scripting or not.

If not, which scripting/programming language should I use for calling classes or methods?

0
Vic Sun  Apr 4, 2020 to Bharath Nunepalli

Is there any reason you need to run these scripts from a shell script? That would definitely be possible and there are plenty of examples you can find on the community with a bit of searching, but I think it would be quite simple to do this in Object Script.

0
Hans-Peter Iten  Apr 6, 2020 to Bharath Nunepalli

You can call methods from command line even like you call routines. Imagine you have a class Test in package TestClasses and a method printData which prints the data to your output device. Then you can call csession instance -"U" namespace "##class(Test).printData("""data""")".

Of course the methods must be ClassMethods. You must test the number of " - signs.  In PowerShell for instance I needed around 14(! sic) "-signs to send a valid command to Caché.

Here the example:

csession ${INSTANCE} -"U" ${NAMESPACE}  "##class(TestClasses.Test).printData(""""""""""""""hello"""""""""""""")"

hello

0
Kevin Johnson · Apr 4, 2020

Hello there Barath,

In order for you to be able to use the name space %SYS in the Secureity.User class I would suggest that you take a closer look into the implementation method and check if you have used or created the methods to interact with data.

An example would be that as follows. Create, Get, Delete methods.

Hope this is useful and helpful. 

0
Bharath Nunepalli · Apr 7, 2020

Thanks all for your responses.

I'm able to come up with a shell script.

ccontrol list | grep -i running > $DB_STATUS_DET1

if [[ -s $DB_STATUS_DET1 ]] then
 csession cache
 s x=##Class(Security.Users).Create("BOBJ","%ALL","P@ssw0rd!","Bob Jones","","","",0,1,"",1,0,"","","","")
else exit
fi

0