通过 bsub (平台 LSF) 提供环境变量

通过 bsub (平台 LSF) 提供环境变量

我似乎无法将环境变量传递给通过 提交给集群调度程序的脚本bsub。当我提交直接使用这些环境变量的命令时,它工作正常,但这些环境变量不能在后续脚本中使用。这是为什么?我该如何修复?

下面是我尝试传递x=1给脚本的一个简单示例:

me@cluster:~[407]$ bsub -I -tty -env 'x=1' 'echo .$x.'
Info: No jobname given, set to: Job_with_no_name
Info: No output file given, set to: output_%J_%I.txt
Info: No memory limit given, set to: 512MB
Info: No runtime limit given, set to: 15min
Job <35590315> is submitted to queue <normal>.
<<Waiting for dispatch ...>>
<<Starting on linuxbmc0243>>
.1.

me@cluster:~[408]$ echo 'echo .$x.' > myechox

me@cluster:~[409]$ more myechox
echo .$x.

me@cluster:~[410]$ chmod +x myechox

me@cluster:~[411]$ bsub -I -tty -env 'x=1' myechox
Info: No jobname given, set to: Job_with_no_name
Info: No output file given, set to: output_%J_%I.txt
Info: No memory limit given, set to: 512MB
Info: No runtime limit given, set to: 15min
Job <35590318> is submitted to queue <normal>.
<<Waiting for dispatch ...>>
<<Starting on linuxbmc1279>>
..

me@cluster:~[412]$ bsub -I -tty -env 'x=1' 'export x;myechox'
Info: No jobname given, set to: Job_with_no_name
Info: No output file given, set to: output_%J_%I.txt
Info: No memory limit given, set to: 512MB
Info: No runtime limit given, set to: 15min
Job <35590340> is submitted to queue <normal>.
<<Waiting for dispatch ...>>
<<Starting on linuxbmc1045>>
..

更新:这有效:

me@cluster:~[456]$ bsub -I -tty -env 'x=1' 'export x=$x;myechox'
Info: No jobname given, set to: Job_with_no_name
Info: No output file given, set to: output_%J_%I.txt
Info: No memory limit given, set to: 512MB
Info: No runtime limit given, set to: 15min
Job <35609253> is submitted to queue <normal>.
<<Waiting for dispatch ...>>
<<Starting on linuxbmc0975>>
.1.

与此同时,我还发现更bsub喜欢与一起使用bsub < scriptfile而不是bsub scriptfile;这似乎是启用嵌入选项的解析所必需的(使用#BSUB),并且它还解释了为什么变量只在本地设置(因为不必调用子脚本)。

然而,现在我也尝试了这个,令人惊讶的是,它不起作用:

me@cluster:~[457]$ bsub -I -tty -env 'x=1' < myechox
Info: No jobname given, set to: Job_with_no_name
Info: No output file given, set to: output_%J_%I.txt
Info: No memory limit given, set to: 512MB
Info: No runtime limit given, set to: 15min
Job <35609459> is submitted to queue <normal>.
<<Waiting for dispatch ...>>
<<Starting on linuxbmc1140>>
..

更新 2:我首先尝试了exporting x,其效果与使用相同-env 'x=1'

me@cluster:~[458]$ export x=1

me@cluster:~[460]$ bsub -I -tty 'echo .$x.'
Info: No jobname given, set to: Job_with_no_name
Info: No output file given, set to: output_%J_%I.txt
Info: No memory limit given, set to: 512MB
Info: No runtime limit given, set to: 15min
Job <35610151> is submitted to queue <normal>.
<<Waiting for dispatch ...>>
<<Starting on linuxbmc1140>>
.1.

me@cluster:~[459]$ bsub -I -tty < myechox
Info: No jobname given, set to: Job_with_no_name
Info: No output file given, set to: output_%J_%I.txt
Info: No memory limit given, set to: 512MB
Info: No runtime limit given, set to: 15min
Job <35609990> is submitted to queue <normal>.
<<Waiting for dispatch ...>>
<<Starting on linuxbmc1140>>
..

更新 3:这再次有效,我认为这是我的问题的答案:

me@cluster:~[571]$ (echo export x=$x && cat myechox) | bsub -I -tty
Info: No jobname given, set to: Job_with_no_name
Info: No output file given, set to: output_%J_%I.txt
Info: No memory limit given, set to: 512MB
Info: No runtime limit given, set to: 15min
Job <35641024> is submitted to queue <normal>.
<<Waiting for dispatch ...>>
<<Starting on linuxbmc1045>>
.1.

相关内容