BookmarkSubscribeRSS Feed

Finding the Metadata owner of a Workspace session or SASWork directory on Linux

Started ‎09-18-2020 by
Modified ‎07-21-2018 by
Views 3,536

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

Comments

Nice 🙂

Version history
Last update:
‎07-21-2018 10:07 AM
Updated by:
Contributors

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Tags