Our customers are often surprised that ESM is able to reconcile token-authenticated Workspace sessions and SASWork directories with the Metadata username of their owner. At least on Linux, this information is fairly easy to get to and does not require our product at all. Here's one way it can be done.
Finding the Metadata owner of a Workspace session
When the Object Spawner spawns a Workspace session, it sets the name of the Metadata user that it belongs as an environment variable called METAUSER. The environment variables that were set when a Linux process was started can be accessed via the proc filesystem, by reading the /proc/$pid/environ file (the executing user needs appropriate permissions to do this). The entries in this file not in the most readable as they're separated by a null byte, so to pretty print the entries use one of the following:
strings /proc/[pid]/environ
or
xargs -n -0 < /proc/[pid]/environ
So, if you often find yourself in the situation where you have the PID of a Workspace session process and need to know who that process is owned by, add the following to your user's .bashrc (explainshell😞
# usage: pidtometa [pid]
function pidtometa() {
sudo strings /proc/${1}/environ | grep METAUSER | cut -d '=' -f 2
}
and you'll be able to use it like this:
$ pidtometa 3747
drjim@!*(generatedpassworddomain)*!
Easy.
Finding the Metadata owner of a SASWork or SASUtil directory
Building on the above, if you often find yourself needing to know who a particular SASWork or Util directory is owned by, also add this to the same .bashrc (explainshell😞
# usage: dirtometa [saswork or util directory]
function dirtometa() {
pidtometa $(( 16#$(echo "$(basename ${1})" | cut -d "_" -f 2 | cut -b 10-) ));
}
and you'll be able to use it like this:
$ dirtometa /data/saswork/SAS_workC02600001647_apps.boemskats.com/SAS_work3D2200001647_apps.boemskats.com
drjim@!*(generatedpassworddomain)*!
Note that for shared environments such as SAS GRID, these functions must be executed on the host that the process is running on, as the /proc info will be local to each host.
If the above helps, you may also want to check out worktop (where some of that dirtometa function code is borrowed from). Also, if you spend a lot of your time doing this kind of thing, you may want to check out Boemska ESM.
Nik
... View more