# Hook to delete job on wrong path

**URL:** <https://community.openpbs.org/t/hook-to-delete-job-on-wrong-path/1792>\
**Category:** Users/Site Administrators\
**Created:** [September 27, 2019, 4:39pm UTC](https://community.openpbs.org/t/hook-to-delete-job-on-wrong-path/1792 "2019-09-27T16:39:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![daniel](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.openpbs.org/daniel/32/630_2.png) [@daniel](https://community.openpbs.org/u/daniel)\
**Post date:** [September 27, 2019, 4:39pm UTC](https://community.openpbs.org/t/hook-to-delete-job-on-wrong-path/1792/1 "2019-09-27T16:39:28Z")

</div>

Hi guys

I need a help to write a hook. I would like to delete a job if job’s path is something like /home/username, eg.

I have read the PBS hooks guide, but I’am in dought on how to do it.

I think that I need a pre-execution hook like this:

create hook deny\_home  
import hook deny\_home application/x-python default /hooks/deny\_home\_script.py  
set hook deny\_home event = queuejob  
set hook deny\_home order = 2  
set hook deny\_home alarm = 60

and the python script content is:

import pbs  
import sys

try:  
e = pbs.event()  
j = e.job

```
if '/home' in j.Submit_arguments:
	e.reject("Performing tasks in home directory is not allowed")

```

except SystemExit:  
pass

except:  
e.reject(“Performing tasks in home directory is not allowed”)

Is it right?

---

<div class="post-metadata">

**Author:** ![gabe](https://avatars.discourse-cdn.com/v4/letter/g/5daacb/32.png) [@gabe](https://community.openpbs.org/u/gabe)\
**Post date:** [September 27, 2019, 6:21pm UTC](https://community.openpbs.org/t/hook-to-delete-job-on-wrong-path/1792/2 "2019-09-27T18:21:10Z")

</div>

@Daniel: What exactly do you mean by “job’s path”? In the environment during QUEUEJOB, there are a few variables available, including `j.Variable_List['PBS_O_HOME']` and `j.Variable_List['PBS_O_WORKDIR']`. `PBS_O_HOME` is the path to the requestor’s home directory on the submission host (not the execution host or server) and `PBS_O_WORKDIR` is the directory on the submission host in which the requestor ran `qsub`.

I recommend enabling debugging for the hook (`set hook deny_home debug = true`), which will result in some members and methods for the queuejob stage of the hook being written to `/var/spool/pbs/server_priv/hooks/tmp` (or equivalent path if your PBS\_HOME is not `/var/spool/pbs`) on your PBS server. That information can be very useful for understanding what exactly is available to the hook when it runs. Everything is documented in the PBS Hooks guide, but not always easy to find.

---

<div class="post-metadata">

**Author:** ![daniel](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.openpbs.org/daniel/32/630_2.png) [@daniel](https://community.openpbs.org/u/daniel)\
**Post date:** [September 27, 2019, 6:57pm UTC](https://community.openpbs.org/t/hook-to-delete-job-on-wrong-path/1792/3 "2019-09-27T18:57:00Z")

</div>

Hi @gabe, how are you doing?

My cluster has 2 network drives. The /home directory and the /scratch directory. /home is a non-clustered network drive (provided by a non-clustered file server). And /scratch is inside the cluster with inifiband, etc. Both of them are acessible in the entire cluster.

I would like to prevent users from running their jobs in this /home and only allow in /scratch.

We use a simulator that has a .dat input file. I would like to verify that this if .dat file is in /home/user/file.dat, the job should be deleted.

Thanks

---

<div class="post-metadata">

**Author:** ![adarsh](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@adarsh](https://community.openpbs.org/u/adarsh)\
**Post date:** [September 29, 2019, 9:09pm UTC](https://community.openpbs.org/t/hook-to-delete-job-on-wrong-path/1792/4 "2019-09-29T21:09:24Z")

</div>

@daniel, please try this queuejob hook

```
import os
import sys
import pbs 

e = pbs.event()
j = e.job
who = str(e.requestor)

pbs.logmsg(pbs.LOG_DEBUG, "PBS_O_WORKDIR is = %s" % str(j.Variable_List['PBS_O_WORKDIR']))
user_home_path=os.path.join("/home",who)
pbs.logmsg(pbs.LOG_DEBUG, "USER HOME directory is is = %s" % user_home_path)
if user_home_path==str(j.Variable_List['PBS_O_WORKDIR']):
	e.reject("Please submit the job or qsub from a different location other than home directory")
```

---

<div class="post-metadata">

**Author:** ![daniel](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.openpbs.org/daniel/32/630_2.png) [@daniel](https://community.openpbs.org/u/daniel)\
**Post date:** [September 30, 2019, 3:47pm UTC](https://community.openpbs.org/t/hook-to-delete-job-on-wrong-path/1792/5 "2019-09-30T15:47:54Z")

</div>

Hello @adarsh

The solution works perfectly!!! My users are going crazy! =D

Many thanks!

---

<div class="post-metadata">

**Author:** ![adarsh](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@adarsh](https://community.openpbs.org/u/adarsh)\
**Post date:** [September 30, 2019, 4:37pm UTC](https://community.openpbs.org/t/hook-to-delete-job-on-wrong-path/1792/6 "2019-09-30T16:37:01Z")

</div>

Nice one 🙂 Thank you @daniel
