#!/bin/csh
#
# Michael L. Love, Tue Aug 15 14:14:26 EDT 2006, GPL
#
# loop2pipe-1.3
#
# To pipe from a foreach loop, fill a buffer,
# then pipe out the result as below.
#

setenv theBuffer

foreach i (` cat /etc/hosts|grep 'n..$'|head -30 |cut -f3`)

 # append to comma-delimited list
 setenv theBuffer `echo $theBuffer``qmgr -c "list node "$i | grep -A1 Node`','

end

echo

# pipe out the result as desired
echo $theBuffer | sed s/','/'\n'/g | grep job-exclusive | sort +2
echo $theBuffer | sed s/','/'\n'/g | grep free | sort +2
echo $theBuffer | sed s/','/'\n'/g | grep offline | sort +2

echo

echo -n 'nodes_free = '
echo $theBuffer | sed s/','/'\n'/g | grep free | wc -l
echo -n 'nodes_offline = '
echo $theBuffer | sed s/','/'\n'/g | grep offline | wc -l
echo -n 'nodes_used = '
echo $theBuffer | sed s/','/'\n'/g | grep job-exclusive | wc -l

echo `qmgr -c 'list server' | grep total_jobs`
