--- /dev/null
+#!/bin/bash
+
+Usage () {
+echo "USAGE: $0 <permission group name>"
+exit 1
+}
+
+GROUP_NAME="$1"
+PG_USER="evergreen"
+PSQL="/usr/bin/psql"
+PG_DB="evergreen"
+
+
+if [ -z $GROUP_NAME ]; then
+ Usage
+fi
+read -d '' SQL <<EOF
+select perm.code as "Permission",
+ perm.description as "Description",
+ grp.name as "Permission Level",
+ case
+ when map.depth = 0 then 'Consortium'
+ when map.depth = 1 then 'System'
+ when map.depth = 2 then 'Branch'
+ end as "Depth",
+ case
+ when map.grantable = true then 'Grantable'
+ when map.grantable = false then 'Not Grantable'
+ end as "Grantability"
+from permission.grp_tree grp
+ join permission.grp_perm_map map on (map.grp = grp.id)
+ join permission.perm_list perm on (map.perm = perm.id)
+where grp.id in (
+ select id
+ from permission.grp_ancestors(
+ (select id
+ from permission.grp_tree
+ where name = '$GROUP_NAME')
+ )
+ )
+ order by 1, 2;
+EOF
+
+PGUSER="$PG_USER" "$PSQL" -A --pset footer --field-separator ',' -o "$GROUP_NAME-perms.out" -c "$SQL" "$PG_DB"
+