Skip to content

Instantly share code, notes, and snippets.

@hartfordfive
Created April 2, 2015 19:55
Show Gist options
  • Save hartfordfive/c8e1097a417ff9c3c192 to your computer and use it in GitHub Desktop.
Save hartfordfive/c8e1097a417ff9c3c192 to your computer and use it in GitHub Desktop.
Get list of open files for a given user
#!/bin/bash
OUTPUT=`lsof -X -c $1 | egrep -v '\.logstash-forwarder' | egrep -E '[0-9]+r\s+REG' | awk '{print $9}'`
case "$2" in
'json')
FILES=`printf ",\"%s\"" \${OUTPUT[@]}`
echo "{\"open_files\": [${FILES:1:${#FILES}-1}]}"
;;
*)
for F in "$OUTPUT"
do
echo "$F"
done
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment