# Setting enviroment variable

**URL:** <https://community.openpbs.org/t/setting-enviroment-variable/4111>\
**Category:** Users/Site Administrators\
**Created:** [April 23, 2025, 11:21am UTC](https://community.openpbs.org/t/setting-enviroment-variable/4111 "2025-04-23T11:21:47Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![fnevgeny](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.openpbs.org/fnevgeny/32/375_2.png) [@fnevgeny](https://community.openpbs.org/u/fnevgeny)\
**Post date:** [April 23, 2025, 11:21am UTC](https://community.openpbs.org/t/setting-enviroment-variable/4111/1 "2025-04-23T11:21:47Z")

</div>

Hello,

Is there a way to make PBS set (for jobs) environment variables depending on resources requested in the `select` statement, similar to `ncpus => $NCPUS`?

---

<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:** [April 23, 2025, 12:06pm UTC](https://community.openpbs.org/t/setting-enviroment-variable/4111/2 "2025-04-23T12:06:40Z")

</div>

Creating a wrapper script to get the inputs from the user , creates the script, assign the enviroment varilable with the script $NCPUS, $MEM, $WALLTIME, $LICENSE\_SERVER , $LD\_LIBRARY\_PATHs and qsub that script.created within the wrapper.

---

<div class="post-metadata">

**Author:** ![fnevgeny](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.openpbs.org/fnevgeny/32/375_2.png) [@fnevgeny](https://community.openpbs.org/u/fnevgeny)\
**Post date:** [April 23, 2025, 5:28pm UTC](https://community.openpbs.org/t/setting-enviroment-variable/4111/3 "2025-04-23T17:28:22Z")

</div>

No, I mean creating the environments without users changing anything in their scripts etc, completely transparently. I guess the only option is a hook, right?

---

<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:** [April 24, 2025, 7:58am UTC](https://community.openpbs.org/t/setting-enviroment-variable/4111/4 "2025-04-24T07:58:37Z")

</div>

> [@fnevgeny](#):
>
> I guess the only option is a hook, right?

Yes, hooks would help here for sure.  
converting the values into Variable\_List.

---

<div class="post-metadata">

**Author:** ![fnevgeny](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.openpbs.org/fnevgeny/32/375_2.png) [@fnevgeny](https://community.openpbs.org/u/fnevgeny)\
**Post date:** [April 28, 2025, 2:39pm UTC](https://community.openpbs.org/t/setting-enviroment-variable/4111/5 "2025-04-28T14:39:06Z")

</div>

> [@adarsh](#):
>
> converting the values into Variable\_List.

Wouldn’t accessing `pbs.event().job.Resource_List["ncpus"]` etc. suffice?

---

<div class="post-metadata">

**Author:** ![fnevgeny](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.openpbs.org/fnevgeny/32/375_2.png) [@fnevgeny](https://community.openpbs.org/u/fnevgeny)\
**Post date:** [April 28, 2025, 3:09pm UTC](https://community.openpbs.org/t/setting-enviroment-variable/4111/6 "2025-04-28T15:09:11Z")

</div>

Interestingly, `job.Resource_List["ncpus"]` does work, but I cannot access similarly a _custom_ resource. Why is that?

---

<div class="post-metadata">

**Author:** ![fnevgeny](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.openpbs.org/fnevgeny/32/375_2.png) [@fnevgeny](https://community.openpbs.org/u/fnevgeny)\
**Post date:** [April 29, 2025, 8:10am UTC](https://community.openpbs.org/t/setting-enviroment-variable/4111/7 "2025-04-29T08:10:03Z")

</div>

OK, I see it in the Hooks guide, 5.2.4.1:

```auto
Hooks have more access to built-in resources than they do to custom resources. All hooks can read built-in resources.
All event hooks that run at the server can read all custom resources via pbs.event(), as well as via pbs.server(). How-
ever, hooks that run at the execution host can read custom resources only via pbs.server(). So for example if a job
requests a custom resource, a runjob hook can read the resource, but an execjob_begin hook cannot.

```

So, it sounds like the intended behavior, but I fail to understand why it was deemed desirable.

---

<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:** [April 29, 2025, 10:24pm UTC](https://community.openpbs.org/t/setting-enviroment-variable/4111/8 "2025-04-29T22:24:22Z")

</div>

The 2024 Admin guide, in section **5.14.2.5** says

> You can make it faster for execution hooks to read custom job resources. Execution hooks cannot read custom job resources via the event, only via the server. However, you can cache a copy of a custom job resource at the MoMs for faster local reading by execution hooks, by setting the _m_ flag for the resource. The job resources that can be cached are found in the following job attributes:
> 
> - exec\_vnode
> - Resource\_List
> - resources\_used

Would this handle your use-case?

---

<div class="post-metadata">

**Author:** ![fnevgeny](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.openpbs.org/fnevgeny/32/375_2.png) [@fnevgeny](https://community.openpbs.org/u/fnevgeny)\
**Post date:** [April 30, 2025, 7:42am UTC](https://community.openpbs.org/t/setting-enviroment-variable/4111/9 "2025-04-30T07:42:28Z")

</div>

Great, it works! I wasn’t aware of this flag; in fact, I can’t find it documented. It appears neither in “Table 5-9: Resource Accumulation Flags” nor in “Table 5-11: Resource Permission Flags”. In addition to the section you cited, I see this flag mentioned under “7.4.1 Create Container Resources”, but without explaining its meaning.

---

<div class="post-metadata">

**Author:** ![agurban](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.openpbs.org/agurban/32/67_2.png) [@agurban](https://community.openpbs.org/u/agurban)\
**Post date:** [June 26, 2025, 3:44pm UTC](https://community.openpbs.org/t/setting-enviroment-variable/4111/10 "2025-06-26T15:44:33Z")

</div>

Good point. I’ve filed a doc bug for this.
