Finding all host groups in which a Grid Engine host is contained (2014-12-09)

There is no direct way in Grid Engine for getting all host groups in which one particular host is part of. But Grid Engine offers a mighty command qconf -shgrp_resolved which returns all hosts of a hostgroup (also when the hostgroup itself contains other hostgroups recursively).

Following simple shell script returns all hostgroups of which the host given as first parameter to the script is part of.

for hgrp in `qconf -shgrpl`; do
    for h in `qconf -shgrp_resolved $hgrp`; do
        if [ "$h" = "$host" ]; then
            echo $hgrp

Update: Alexandru's one liner for this task is easier to setup as an simple alias (thanks for the hint).

for aa in $(qconf -shgrpl) ; do qconf -shgrp $aa | grep -q $1 && echo $aa ; done