You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Linux终端通过bsub提交含多引号Windows命令报错求助

Linux终端通过bsub提交Windows关机任务报错的解决

问题描述

我需要在Linux终端执行以下命令,通过bsub将任务提交至Windows机器mtbsvr2:

"bsub -J shutdownMachines -o //noi/out.txt -e //noi/err.txt -m mtbsvr2 -q win_normal "for /f %i in ( 'bhosts -w pov_test ^| cut -d " " -f1 ^| tail -n +2' ) do shutdown -m \%i /r /t 02"

执行后//noi/err.txt中报错:

The syntax of the command is incorrect.

尝试多种单双引号组合仍无法运行,寻求解决方法。

问题根源

核心是Linux Shell与Windows CMD的语法、引号/转义规则冲突,直接在Linux命令里嵌套复杂Windows脚本会导致命令解析彻底错乱,同时还存在Windows批处理变量格式、关机命令参数的错误。

解决步骤

1. 编写独立的Windows批处理脚本

创建一个shutdown_hosts.bat文件,把Windows侧要执行的逻辑单独写进去:

@echo off
:: 遍历bhosts输出的目标机器,执行关机命令
for /f "delims=" %%i in ('bhosts -w pov_test ^| cut -d " " -f1 ^| tail -n +2') do (
    shutdown -m \\%%i /r /t 2
)
  • 注意:Windows批处理脚本中for循环变量必须用%%i(交互模式才用%i)
  • shutdown的-m参数需要双反斜杠\\指定远程机器
  • 添加delims=避免机器名被空格截断

2. 放置脚本到共享路径

将shutdown_hosts.bat放到Windows机器可访问的共享路径,比如//noi/shutdown_hosts.bat,确保mtbsvr2有权限读取。

3. 用bsub调用批处理脚本

在Linux终端执行简化后的bsub命令,直接调用Windows的cmd来运行脚本:

bsub -J shutdownMachines -o //noi/out.txt -e //noi/err.txt -m mtbsvr2 -q win_normal "cmd /c //noi/shutdown_hosts.bat"

额外验证建议

  • 先在mtbsvr2本地手动运行shutdown_hosts.bat,确认脚本本身能正常执行,排除脚本逻辑问题
  • 检查bsub提交的任务状态,用bjobs命令查看是否成功调度到mtbsvr2

内容的提问来源于stack exchange,提问作者PPP

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 03:55:15