# PBS interpreting server\_dyn\_res script output as 0

**URL:** <https://community.openpbs.org/t/pbs-interpreting-server-dyn-res-script-output-as-0/3965>\
**Category:** Users/Site Administrators\
**Created:** [August 15, 2024, 7:42pm UTC](https://community.openpbs.org/t/pbs-interpreting-server-dyn-res-script-output-as-0/3965 "2024-08-15T19:42:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgasp](https://avatars.discourse-cdn.com/v4/letter/m/3be4f8/32.png) [@mgasp](https://community.openpbs.org/u/mgasp)\
**Post date:** [August 15, 2024, 7:42pm UTC](https://community.openpbs.org/t/pbs-interpreting-server-dyn-res-script-output-as-0/3965/1 "2024-08-15T19:42:35Z")

</div>

I’ve followed the instructions in 5.14.6.3.ii of the PBS Pro Guide (20.0.1).

My flexlm script looks like this:

```auto
#!/bin/bash
# some comments...
raw=($(lmutil lmstat -c $2 -f $1 | grep Total | awk '{ print $0 }'))
avail=$((${raw[5]}-${raw[10]}))
total=${raw[5]}
echo $((avail))
resv=$(printf %.0f $(echo "$total*((100-$3)*0.01)" | bc)) #Percent to reserve for non-PBS jobs.

if ["$avail" -le "$resv"];then
        echo $avail
else
        echo $resv
fi

```

My qsub statement (which should pass and submit for execution) looks like this:

```auto
qsub -l msimhdlsim=1 ./scripts/echo_host.sh

```

Looking at sched\_log i get this:

```auto
08/15/2024 15:16:29;0040;pbs_sched;Job;73.pbsserv;Insufficient amount of server resource: msimhdlsim (R: 1 A: 0 T: 0)
08/15/2024 15:16:29;0040;pbs_sched;Job;73.pbsserv;Job will never run with the resources currently configured in the complex
08/15/2024 15:16:29;0080;pbs_sched;Job;74.pbsserv;Considering job to run

```

sched\_config server\_dyn\_res\_line:

```auto
server_dyn_res: "msimhdlsim !/opt/pbs/server_dyn_res_scripts/lmquery msimhdlsim 8888@mylicserv 10"

```

sched\_config resources:

```auto
resources: "ncpus, mem, arch, host, vnode, aoe, eoe, qlist, msimhdlsim"

```

resourcedef:

```auto
qlist type=string_array flag=h
msimhdlsim type=long

```

I’m not quite sure what i’m missing here. When i run the script with the arguments as entered in sched\_config i get the expected output:

```auto
[root@pbsserv pbs]# /opt/pbs/server_dyn_res_scripts/lmquery msimhdlsim 8888@mylicserv 10
16

```

Any help is appreciated

---

<div class="post-metadata">

**Author:** ![vchlum](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.openpbs.org/vchlum/32/93_2.png) [@vchlum](https://community.openpbs.org/u/vchlum)\
**Post date:** [August 16, 2024, 5:46am UTC](https://community.openpbs.org/t/pbs-interpreting-server-dyn-res-script-output-as-0/3965/2 "2024-08-16T05:46:16Z")

</div>

Hi!

Why do you have the line `echo $((avail))` ? Isn’t it a debug line?

I recommend adding `#!/bin/bash` on the first line of your flexlm script. Otherwise, the server\_dyn\_res query uses the`/bin/sh` interpreter.

Check the sched\_log for `server_dyn_res` lines at the beginning of the scheduler iteration.

---

<div class="post-metadata">

**Author:** ![mgasp](https://avatars.discourse-cdn.com/v4/letter/m/3be4f8/32.png) [@mgasp](https://community.openpbs.org/u/mgasp)\
**Post date:** [August 16, 2024, 6:40pm UTC](https://community.openpbs.org/t/pbs-interpreting-server-dyn-res-script-output-as-0/3965/3 "2024-08-16T18:40:50Z")

</div>

> [@vchlum](#):
>
> Why do you have the line `echo $((avail))` ? Isn’t it a debug line?

The manual says: “The script must return the value via stdout in a single line ending with a newline”. FWIW i’ve tried doing

`$avail`

`echo $avail`

with no difference.

> [@vchlum](#):
>
> I recommend adding `#!/bin/bash` on the first line of your flexlm script. Otherwise, the server\_dyn\_res query uses the`/bin/sh` interpreter

I didn’t include the first few lines but I already have. I’ll edit the excerpt above to reflect that.

> [@vchlum](#):
>
> Check the sched\_log for `server_dyn_res` lines at the beginning of the scheduler iteration.

Nothing that i can see:

```auto
08/16/2024 14:37:26;0080;pbs_sched;Req;;Starting Scheduling Cycle
08/16/2024 14:37:26;0040;pbs_sched;Node;pbscompute1;Unknown Node State: initializing on add operation
08/16/2024 14:37:26;0040;pbs_sched;Node;pbscompute1;Unknown Node State: initializing
08/16/2024 14:37:26;0080;pbs_sched;Job;76.pbsserv;Considering job to run
08/16/2024 14:37:26;0040;pbs_sched;Job;76.pbsserv;Insufficient amount of server resource: msimhdlsim (R: 50 A: 0 T: 0)
08/16/2024 14:37:26;0040;pbs_sched;Job;76.pbsserv;Job will never run with the resources currently configured in the complex
08/16/2024 14:37:26;0080;pbs_sched;Job;93.pbsserv;Considering job to run
08/16/2024 14:37:26;0040;pbs_sched;Job;93.pbsserv;Insufficient amount of server resource: msimhdlsim (R: 1 A: 0 T: 0)
08/16/2024 14:37:26;0040;pbs_sched;Job;93.pbsserv;Job will never run with the resources currently configured in the complex
08/16/2024 14:37:26;0080;pbs_sched;Job;94.pbsserv;Considering job to run
08/16/2024 14:37:26;0040;pbs_sched;Job;94.pbsserv;Insufficient amount of server resource: msimhdlsim (R: 1 A: 0 T: 0)
08/16/2024 14:37:26;0040;pbs_sched;Job;94.pbsserv;Job will never run with the resources currently configured in the complex
08/16/2024 14:37:26;0080;pbs_sched;Req;;Leaving Scheduling Cycle

```

---

<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:** [August 17, 2024, 1:18pm UTC](https://community.openpbs.org/t/pbs-interpreting-server-dyn-res-script-output-as-0/3965/4 "2024-08-17T13:18:35Z")

</div>

Could you please do this test

```auto
server_dyn_res: "msimhdlsim !/opt/pbs/server_dyn_res_scripts/lmquery msimhdlsim 8888@mylicserv 10"

```

Comment the above line in $PBS\_HOME/sched\_priv/sched\_config

Add the below line

```auto
server_dyn_res: "msimhdlsim !/opt/pbs/server_dyn_res_scripts/check.sh

```

```auto
cat /opt/pbs/server_dyn_res_scripts/check.sh
#!/bin/bash
echo "100"

```

```auto
chmod +x /opt/pbs/server_dyn_res_scripts/check.sh
.//opt/pbs/server_dyn_res_scripts/check.sh
100

```

`kill -HUP <pid of the scheduler>`

```auto
Submit and check the scheduler message 

qsub -l msimhdlsim=101 ./scripts/echo_host.sh
qstat -answ1

```

---

<div class="post-metadata">

**Author:** ![mgasp](https://avatars.discourse-cdn.com/v4/letter/m/3be4f8/32.png) [@mgasp](https://community.openpbs.org/u/mgasp)\
**Post date:** [August 19, 2024, 8:03pm UTC](https://community.openpbs.org/t/pbs-interpreting-server-dyn-res-script-output-as-0/3965/5 "2024-08-19T20:03:56Z")

</div>

Looks like the test worked. I submitted two jobs:

```auto
qsub -l msimhdlsim=101 ./scripts/echo_host.sh 
107.pbsserv
qsub -l msimhdlsim=99 ./scripts/echo_host.sh
108.pbsserv

```

```auto
08/19/2024 15:28:14;0080;pbs_sched;Job;107.pbsserv;Considering job to run
08/19/2024 15:28:14;0040;pbs_sched;Job;107.pbsserv;Insufficient amount of server resource: msimhdlsim (R: 101 A: 100 T: 100)
08/19/2024 15:28:14;0040;pbs_sched;Job;107.pbsserv;Job will never run with the resources currently configured in the complex
08/19/2024 15:28:14;0080;pbs_sched;Job;108.pbsserv;Considering job to run
08/19/2024 15:28:14;0040;pbs_sched;Job;108.pbsserv;Job run

```

For confirmation, my `check.sh`:

```auto
#!/bin/bash
echo "100"

```

FWIW, i added `echo "100"` and `echo "50"` to `lmquery` in place of the previous echo statements:

```auto
#!/bin/bash
# some comments...
###########################################################
raw=($(lmutil lmstat -c $2 -f $1 | grep Total | awk '{ print $0 }')) #'{avail=($6-$11); total=$6}'
avail=$((${raw[5]}-${raw[10]}))
total=${raw[5]}
resv=$(printf %.0f $(echo "$total*((100-$3)*0.01)" | bc))

#echo "available: $avail reserve: $resv"
if ["$avail" -le "$resv"];then
        echo "100"
        #echo $avail
else
        echo "50"
        #echo $resv
fi

```

And this behaves as expected:

```auto
qsub -l msimhdlsim=101 ./scripts/echo_host.sh 
114.pbsserv

qstat -answ1

pbsserv: 
                                                                                                   Req'd Req'd Elap
Job ID Username Queue Jobname SessID NDS TSK Memory Time S Time
------------------------------ --------------- --------------- --------------- -------- ---- ----- ------ ----- - -----
114.pbsserv pbs_user qmed echo_host.sh -- 1 2 400mb -- Q -- -- 
   Can Never Run: Insufficient amount of server resource: msimhdlsim (R: 101 A: 50 T: 50)

```

---

<div class="post-metadata">

**Author:** ![mgasp](https://avatars.discourse-cdn.com/v4/letter/m/3be4f8/32.png) [@mgasp](https://community.openpbs.org/u/mgasp)\
**Post date:** [August 21, 2024, 6:24pm UTC](https://community.openpbs.org/t/pbs-interpreting-server-dyn-res-script-output-as-0/3965/6 "2024-08-21T18:24:26Z")

</div>

Hi all,

I solved this issue by using the absolute path to lmutil:

```auto
#!/bin/bash
# some comments...
raw=($(/usr/local/sbin/lmutil lmstat -c $2 -f $1 | grep Total | awk '{ print $0 }'))
avail=$((${raw[5]}-${raw[10]}))
.....

```

Even though root has lmutil in its path, it appears the shell PBS runs the dyn\_res scripts does not take the full root env.
