# How To See The Sbatch Command That Gets Run

**URL:** https://discourse.openondemand.org/t/how-to-see-the-sbatch-command-that-gets-run/1280
**Category:** Get Help
**Tags:** question
**Created:** [January 21, 2021, 9:15pm UTC](https://discourse.openondemand.org/t/how-to-see-the-sbatch-command-that-gets-run/1280 "2021-01-21T21:15:21Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![cupdike](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/cupdike/32/435_2.png) [@cupdike](https://discourse.openondemand.org/u/cupdike)
#### Post date: [January 21, 2021, 9:15pm UTC](https://discourse.openondemand.org/t/how-to-see-the-sbatch-command-that-gets-run/1280/1 "2021-01-21T21:15:21Z")

</div>

I’m trying to apply a GPU with Slurm using native attributes. It runs but the GPUs aren’t being reserved as expected. How can I see the actual sbatch command that is running to know what is going on? My actual submit.yml.erb file is given below:

```
batch_connect:
  template: "basic"
<%-
  slurm_args = if gpu_switch == 1
                 ["--gpus-per-node", "1", "--gres", "gpu:1"]
               else
                 []
               end
-%>

script:
  native:
  <%- slurm_args.each do |arg| %>
    - "<%= arg %>"
  <%- end %>
```

---

<div class="post-metadata">

### Author: ![jeff.ohrstrom](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/jeff.ohrstrom/32/136_2.png) [@jeff.ohrstrom](https://discourse.openondemand.org/u/jeff.ohrstrom)
#### Post date: [January 21, 2021, 9:24pm UTC](https://discourse.openondemand.org/t/how-to-see-the-sbatch-command-that-gets-run/1280/2 "2021-01-21T21:24:56Z")

</div>

My guess is it’s a type issue where `gpu_switch` is a string not an integer.

Either turn gpu switch into a integer with `gpu_switch.to_i` or compare it against the string 1 like `== "1"`.

Also, just as an aside to style, you may want to put the ERB `<%- %>` block at the top for readability.

```auto
<%- 
   # do all the computations up here
%>
---
batch_connect:
  # and so on

```

---

<div class="post-metadata">

### Author: ![cupdike](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/cupdike/32/435_2.png) [@cupdike](https://discourse.openondemand.org/u/cupdike)
#### Post date: [January 21, 2021, 9:41pm UTC](https://discourse.openondemand.org/t/how-to-see-the-sbatch-command-that-gets-run/1280/3 "2021-01-21T21:41:31Z")

</div>

Yep, that was it… thanks!

Is there a way to see the sbatch command that is actually getting run? And any other tips for debugging these kinds of issues?

---

<div class="post-metadata">

### Author: ![jeff.ohrstrom](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/jeff.ohrstrom/32/136_2.png) [@jeff.ohrstrom](https://discourse.openondemand.org/u/jeff.ohrstrom)
#### Post date: [January 21, 2021, 9:55pm UTC](https://discourse.openondemand.org/t/how-to-see-the-sbatch-command-that-gets-run/1280/4 "2021-01-21T21:55:59Z")

</div>

Yea you can see the command being run in `/var/log/ondemand-nginx/USER/error.log`. For this error, I just kinda knew from experience that they’re _always_ strings - maybe I’d run into the same issue once or twice. Something like this, `gpu_switch` isn’t going to be in the sbatch command, but you can see what all these templates got templated with in the `user_defined_context.json` in the job’s session directory (the link in the card). This will indicate whether or not flags are being correctly passed from the form to the submit.yml.

---

<div class="post-metadata">

### Author: ![cupdike](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/cupdike/32/435_2.png) [@cupdike](https://discourse.openondemand.org/u/cupdike)
#### Post date: [January 21, 2021, 10:28pm UTC](https://discourse.openondemand.org/t/how-to-see-the-sbatch-command-that-gets-run/1280/5 "2021-01-21T22:28:11Z")

</div>

I’m not seeing much useful in error.log. The user\_defined\_context.json is definitely helpful.  
If I drop print statements into my ERB block in submit.yml.erb, I cannot find the output anywhere. Is there a way to print out info like this?

---

<div class="post-metadata">

### Author: ![jeff.ohrstrom](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/jeff.ohrstrom/32/136_2.png) [@jeff.ohrstrom](https://discourse.openondemand.org/u/jeff.ohrstrom)
#### Post date: [January 21, 2021, 11:17pm UTC](https://discourse.openondemand.org/t/how-to-see-the-sbatch-command-that-gets-run/1280/6 "2021-01-21T23:17:48Z")

</div>

No, but if you’re in a development environment - that is, in your home directory where only you have access to this app - I have raised errors with debug messages like:

```ruby
<%-
  raise StandardError.new("the value of the things I'm looking for is: #{the_thing.inspect}")
-%>

```

---

<div class="post-metadata">

### Author: ![cupdike](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/cupdike/32/435_2.png) [@cupdike](https://discourse.openondemand.org/u/cupdike)
#### Post date: [January 22, 2021, 4:08pm UTC](https://discourse.openondemand.org/t/how-to-see-the-sbatch-command-that-gets-run/1280/7 "2021-01-22T16:08:41Z")

</div>

Not sure how useful this is, but:

```
% cat submit.yml.erb                      
# Job submission configuration file
#
---

<%-
slurm_args = if gpu_switch.to_i == 1
                 #["--nodes", "#{nodes}", "--ntasks-per-node", "#{ppn}", "--gpus-per-node", "1", "--gres", "vis"]
                 ["--gpus-per-node", "1", "--gres", "gpu:1"]
               else
                 []
               end
-%>

batch_connect:
  template: "basic"

script:
  native:
  <%- slurm_args.each do |arg| %>
    - "<%= arg %>"
  <%- end %>
   - "--exclusive"%                                                                                                                                                                                           

```

### Manually process the template using CLI erb, providing params:

```
% erb -T - gpu_switch="1" submit.yml.erb 

# Job submission configuration file
#
---

batch_connect:
  template: "basic"

script:
  native:

    - "--gpus-per-node"

    - "1"

    - "--gres"

    - "gpu:1"

   - "--exclusive"
```

---

<div class="post-metadata">

### Author: ![jeff.ohrstrom](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/jeff.ohrstrom/32/136_2.png) [@jeff.ohrstrom](https://discourse.openondemand.org/u/jeff.ohrstrom)
#### Post date: [January 22, 2021, 4:43pm UTC](https://discourse.openondemand.org/t/how-to-see-the-sbatch-command-that-gets-run/1280/8 "2021-01-22T16:43:56Z")

</div>

Sure is! If you end the each and end lines with `-%>` instead of `%>` you’ll get rid of the spaces in the array arguments.

Also the last `- "--exclusive"` seems to be off by 1 space.

---

<div class="post-metadata">

### Author: ![westburg.2](https://avatars.discourse-cdn.com/v4/letter/w/0ea827/32.png) [@westburg.2](https://discourse.openondemand.org/u/westburg.2)
#### Post date: [May 26, 2022, 3:43pm UTC](https://discourse.openondemand.org/t/how-to-see-the-sbatch-command-that-gets-run/1280/9 "2022-05-26T15:43:02Z")

</div>


