MasterHD I know you have found your answer but I thought I would share another way
This code is longer but it helps for my specific needs. I actually use pbsnodes commands. Below is a snippet of my code.
@nodes_whole =`pbsnodes -av -s $server | grep "pcpus" `;
$nodes_count = ` pbsnodes -av -s $server | grep "pcpus" | wc -l `;
while($i < $nodes_count){
@cpu_present = split(/\s+/, $nodes_whole[$i]);
$cpu_whole_count += $cpu_present[3];
$i++;
}
I do this because in my script I check things like the amount of cpus , which varies depending on the node the cpus maybe be 4, 8, 16. Also I have multiple clusters which are always changing size and I don't want the script have specific cluster or node info hard coded. Mainly, I do this because when a user submits a job I check to see how many resources they can use . If say they want use a queue and request 200 cpus but on cluster A their job will be queued my script can tell them they will be queued but would not be on cluster b or d. So then they have the option to change before they submit.
I also use it to check for nodes down:
@nodes_down=`pbsnodes -l -s $server `;
I see what resources are in use:
@nodes_used=`pbsnodes -av -s $server | grep "resources_assigned.ncpus" `;
Also in one case I have two clusters running off one head node while I wait for hardware. In that case I check to see what cluster the node is assigned to and then do a count based on the node assigned to that cluster. That way all the users see is another cluster and use the script they way they would for any of the other clusters.
I just mention because I have found a lot of useful ways to use the pbsnodes and it worked well for my particular needs.