Skip to content

Instantly share code, notes, and snippets.

@isaaclw
Last active May 28, 2020 15:47
Show Gist options
  • Save isaaclw/3f56e8813888450eb7f072b297170709 to your computer and use it in GitHub Desktop.
Save isaaclw/3f56e8813888450eb7f072b297170709 to your computer and use it in GitHub Desktop.
Checks a Pid for a variable in the environment #bash #env
#!/bin/bash
# isaac ALL = NOPASSWD: /home/isaac/.bin/sudo_envcat
pid="$1"
if [ "$pid" == 't' ] && [ $(whoami) == 'root' ]; then
exit 0
fi
var="$2"
output=$(cat /proc/$pid/environ | tr '\0' '\n' | grep "$var" | cut -d '=' -f2-)
if [ -n "$DEBUG" ] && [ -n "$output" ]; then
echo "$pid -> $output"
else
echo "$output"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment