# Hook script to get node list and issue command on the head server

**URL:** <https://community.openpbs.org/t/hook-script-to-get-node-list-and-issue-command-on-the-head-server/3302>\
**Category:** Users/Site Administrators\
**Created:** [October 5, 2022, 5:56pm UTC](https://community.openpbs.org/t/hook-script-to-get-node-list-and-issue-command-on-the-head-server/3302 "2022-10-05T17:56:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![rafsalas19](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.openpbs.org/rafsalas19/32/605_2.png) [@rafsalas19](https://community.openpbs.org/u/rafsalas19)\
**Post date:** [October 5, 2022, 5:56pm UTC](https://community.openpbs.org/t/hook-script-to-get-node-list-and-issue-command-on-the-head-server/3302/1 "2022-10-05T17:56:09Z")

</div>

**Functionality desired** : I need a hook script to run on the scheduler node only. I need the to gather the list of compute hosts for a monitoring tool which will get subsequently launched from the hook script.

**The issue** : The event type ‘runjob’ the node list comes up as None. I did try some other event types but they ended up launching the hook script on the compute nodes as opposed to the scheduler. The script only needs to be run at the beginning of the job to gather job id and host lists. Then launch the monitoring tool.

Is this functionality possible w/ PBS hooks?

My hook:  
Hook jobMonitor  
type = site  
enabled = true  
event = runjob  
user = pbsadmin  
alarm = 30  
order = 1  
debug = true  
fail\_action = none

---

<div class="post-metadata">

**Author:** ![speleolinux](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@speleolinux](https://community.openpbs.org/u/speleolinux)\
**Post date:** [October 7, 2022, 4:08am UTC](https://community.openpbs.org/t/hook-script-to-get-node-list-and-issue-command-on-the-head-server/3302/2 "2022-10-07T04:08:41Z")

</div>

Why do you need a hook? “pbsnodes -a” will give you the node list. You might need to explain a bit more detail of what you wish to achieve.  
Mike

---

<div class="post-metadata">

**Author:** ![rafsalas19](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.openpbs.org/rafsalas19/32/605_2.png) [@rafsalas19](https://community.openpbs.org/u/rafsalas19)\
**Post date:** [October 7, 2022, 9:34pm UTC](https://community.openpbs.org/t/hook-script-to-get-node-list-and-issue-command-on-the-head-server/3302/3 "2022-10-07T21:34:35Z")

</div>

Hey Mike,  
Thanks for the reply.  
I think my terminology was a bit off. What I meant by node list was the list of hosts allocated for the job being launched. I need to create a host file associated with the job so that my monitoring tool can assign the pbs job IDs with telemetry coming from the subset of nodes allocated for the job.

So in summary the functionality would be:  
Right before or at the time the job is launched the script runs on the head node to collect the allocated job nodes and creates a host file. The script will then make an API call to my monitoring tool and pass a job ID and host file.

-Rafael

---

<div class="post-metadata">

**Author:** ![speleolinux](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@speleolinux](https://community.openpbs.org/u/speleolinux)\
**Post date:** [October 10, 2022, 1:11am UTC](https://community.openpbs.org/t/hook-script-to-get-node-list-and-issue-command-on-the-head-server/3302/4 "2022-10-10T01:11:27Z")

</div>

Ah, now I understand why you need the hook. Hopefully a hook expert will jump in here and help. I have only written two hooks for queuejob events.

---

<div class="post-metadata">

**Author:** ![dtalcott](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.openpbs.org/dtalcott/32/410_2.png) [@dtalcott](https://community.openpbs.org/u/dtalcott)\
**Post date:** [October 10, 2022, 3:11pm UTC](https://community.openpbs.org/t/hook-script-to-get-node-list-and-issue-command-on-the-head-server/3302/5 "2022-10-10T15:11:15Z")

</div>

I haven’t tested this, but according to Table 5-6 in the PBSHooks document, the runjob hook should have access to the exec\_vnode attribute. You can massage that into a host list.

However, in your original post, you said the hook would also launch a monitoring tool. This is not recommended and will probably not work. Later, you said the hook will contact the tool via an API. This has a better chance of working.

---

<div class="post-metadata">

**Author:** ![rafsalas19](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.openpbs.org/rafsalas19/32/605_2.png) [@rafsalas19](https://community.openpbs.org/u/rafsalas19)\
**Post date:** [October 13, 2022, 8:44pm UTC](https://community.openpbs.org/t/hook-script-to-get-node-list-and-issue-command-on-the-head-server/3302/6 "2022-10-13T20:44:52Z")

</div>

Thanks! Yea still in the design phase and will be going with an API call. I will look into see if I can use the exec\_vnode.

---

<div class="post-metadata">

**Author:** ![speleolinux](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@speleolinux](https://community.openpbs.org/u/speleolinux)\
**Post date:** [October 18, 2022, 4:26am UTC](https://community.openpbs.org/t/hook-script-to-get-node-list-and-issue-command-on-the-head-server/3302/7 "2022-10-18T04:26:01Z")

</div>

Hi

For help in gettting an API working you might find the link below useful. It’s my own small app for monitoring a HPC at my Uni. I use the PBS include file to create a Python API that is more understandable and simple to use. It then called as a Python library.

> [@Released a small web app to show cluster status](https://community.openpbs.org/t/released-a-small-web-app-to-show-cluster-status/1416):
>
> Hi all I have released as open source a small web application to show the nodes, queues and jobs running on a cluster which uses PBS Pro. This is useful for administrators to quickly see the status of the nodes and how busy they are, to check how full each queue is and to see what jobs are running and queued. It’s also useful for users to see this information as well. You can see our working example here: [https://hpc.research.uts.edu.au/status/](https://hpc.research.uts.edu.au/status/) Here is a screenshot: T…

Mike
