Linux / RHEL - Writing Global Value from Cache to STDOUT on the Command Line OS Terminal
Hello,
Is it possible to write global output values to STDOUT, in a similar way to how csession can take routine intput, like below:
(In Cache Terminal)
%SYS>d ##class(%SYSTEM.License).
License Server summary view of active key.
Distributed license use:
Current License Units Used = 1
Maximum License Units Used = 1
License Units Authorized = 200
Local license use:
Current Connections = 1 Maximum Connections = 1
Current Users = 1 Maximum Users = 2
(From Linux OS Terminal)
[jhipp@test-sbox ~]# csession TEST "##class(%SYSTEM.License).
License Server summary view of active key.
Distributed license use:
Current License Units Used = 0
Maximum License Units Used = 1
License Units Authorized = 200
Local license use:
Current Connections = 0 Maximum Connections = 1
Current Users = 1 Maximum Users = 2
This does not work, but I am wondering if there is a recommended solution:
(Cache Terminal)
%SYS>w ##class(Security.System).
8304
(Linux OS Terminal)
[jhipp@test-sbox ~]# csession TEST "##class(Security.System).
<INVALID ARGUMENT>
[jhipp@test-sbox ~]# csession TEST "w ##class(Security.System).
<INVALID ARGUMENT>
A workaround (that I think is a bit clunky, which is why I am asking):
[jhipp@test-sbox ~]# echo -e "w ##class(Security.System).
Node: test-sbox, Instance: TEST
%SYS>
8304
%SYS>
I can parse out the line output with grep or awk, but that is probably not the best way to achieve this.
Thanks,
- James
James, for this one, there is no easy answer. But first, here are some corrections FYI:
So it's this:
csession TEST -U %SYS '##class(Security.System).AutheEnabledGetStored("SYSTEM")'
But the problem is that this expression doesn't output its value, and you can't include "write" at the beginning. You should probably describe exactly what you're trying to do in more detail, and someone here will make a suggestion.
Hey Joel,
Thanks for the input, single quotes is easier than using slashes to escape the double quote characters.
That particular command may not be the best example to accomplish what I am looking for, but it was more of just a general question about the best way to write out global values. For instance, we have a script that checks for Users that exists in Cache, so that requires us to write out a global boolean value for Security.Users.Exists(). And similar things like that.
Thanks,
James
Hello Alexey,
I appreciate your input. This method accomplishes what I mentioned earlier as well in my workaround. I personally do not like using 'EOF' in my scripts because it can be very sensitive with indentation and whitespace. But regardless, with either method I am going to have to parse out the 5th line of output with awk if I just want to return the true value and not the entire Cache terminal output.
I would consider your solution a 'workaround' as well , but you are correct this does work. I just did not know if there was a way to only return the global value to STDOUT much like cconsole can do with routine calls.
Thanks,
James
The simplest way to interact from within bash with Caché looks like this:
Output of Caché `write` and `zwrite` commands will go to STDOUT. As usual, you can redirect it wherever you want, e.g.
csession TEST -U%SYS << EOF >> /home/james/mysession.log
As parsing csession log can be a nasty task, I usually try to avoid it by construct:
Hi James,
Agree with you, parsing terminal output is not the smartest solution. I always try to avoid it using intermediate files. E.g. (from real life):
Here the default DB of the namespace $NspToCheck (or $ZError code) is written to $mydir/db_temp file, than it goes to $DbQms shell variable and processed as needed.
Initial answer was amended.