<p><a href="https://www.ibm.com/docs/en/spectrum-lsf/10.1.0?topic=o-o" rel="nofollow noreferrer">bsub supports some filename placeholders using a percent sign</a>, like <code>%J</code> for the LSF job ID, so you can use that:</p>
<p><code>snakemake ... --cluster &quot;bsub ... -o logs/{name}_%J.out -e logs/{name}_%J.err&quot;</code></p>
<p>That way snakemake will format the cluster command string with its wildcards (like <code>name</code>) as it constructs the bsub command, and then bsub will put the job ID in place in those filenames.  Since Snakemake just sees that as one big command to run for the cluster and doesn't know the details other than formatting the text, I think the two shouldn't clash.</p>

CC BY-SA 4.0
2022-10-14T16:58:57.187Z
Oh my, thank you! That worked!
Dandelion
CC BY-SA 4.0
2022-10-13T14:51:19.907Z
2022-10-13T14:51:19.907Z
Jesse
<p><strong>Background</strong> I am using <a href="https://snakemake.readthedocs.io/en/stable/" rel="nofollow noreferrer"><code>snakemake</code></a> and I want to add the external (cluster) jobid to my cluster output and error log files. Below is my shell script.</p>
<p><code>snakemake --configfiles config/config_resources.yml config/config_parameters.yml --latency-wait 60 --use-conda --printshellcmds --jobname PipeName_{name}.jobid{jobid} --jobs 300 --cluster &quot;bsub -W 480 -n {threads} -M {resources.mem_gb}G -R 'rusage[mem={resources.mem_gb}G]' -o logs/{name}_{jobid}.out -e logs/{name}_{jobid}.err&quot;</code>.</p>
<p>But I only get the internal one in de log name from snakemake (e.g. 1 to 5), instead of the one from the cluster.</p>
<p><strong>Question</strong> How to I get the external job id in there and not the local one made by snakemake? Or where in my shell script did I go wrong?</p>
<p>Cheers and thanks in advance.</p>

<snakemake><hpc>
How to get the external (cluster) job id and not internal snakemake job id in cluster log files?
# How to get the external (cluster) job id and not internal snakemake job id in cluster log files?

(Asked by: username_0 on 2022-10-12)

**Background** I am using [`snakemake`](https://snakemake.readthedocs.io/en/stable/) and I want to add the external (cluster) jobid to my cluster output and error log files. Below is my shell script.

`snakemake --configfiles config/config_resources.yml config/config_parameters.yml --latency-wait 60 --use-conda --printshellcmds --jobname PipeName_{name}.jobid{jobid} --jobs 300 --cluster "bsub -W 480 -n {threads} -M {resources.mem_gb}G -R 'rusage[mem={resources.mem_gb}G]' -o logs/{name}_{jobid}.out -e logs/{name}_{jobid}.err"`.

But I only get the internal one in de log name from snakemake (e.g. 1 to 5), instead of the one from the cluster.

**Question** How to I get the external job id in there and not the local one made by snakemake? Or where in my shell script did I go wrong?

Cheers and thanks in advance.

**Tags:** snakemake, hpc

---

## 1 answers

### Answer by username_1 on 2022-10-13. Score: 1 | Accepted answer

[bsub supports some filename placeholders using a percent sign](https://www.ibm.com/docs/en/spectrum-lsf/10.1.0?topic=o-o), like `%J` for the LSF job ID, so you can use that:

`snakemake ... --cluster "bsub ... -o logs/{name}_%J.out -e logs/{name}_%J.err"`

That way snakemake will format the cluster command string with its wildcards (like `name`) as it constructs the bsub command, and then bsub will put the job ID in place in those filenames. Since Snakemake just sees that as one big command to run for the cluster and doesn't know the details other than formatting the text, I think the two shouldn't clash.

> **Comments:**
> **username_0**: Oh my, thank you! That worked!  

---

