0

我想结合 Windows 批处理脚本和 plink.exe 工具(http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html)并作为循环运行但没有运气,下面是我的。感谢您的帮助

@echo off
for /f %%i in (D:\script\ip.txt) do (
pushd C:\Windows\System32\tools
plink.exe -l root -pw xxxx root@%%i lsb_release -sr | grep 12.04
if ERRORLEVEL 1 (
msg * Sorry, this is NOT a Precise version
exit
) else
(
pushd C:\Windows\System32\tools
msg * Cheers, welcome to Precise!
)
)

或者它只是将 Windows 批处理脚本作为循环运行。

if it is Ubuntu 10.04
do nothing
else if (meant, it's Ubuntu 12.04)
already LibreOffice installed
do nothing
else
install LibreOffice
exit

并重复到 ip.txt 文件中的下一个 IP 地址

4

1 回答 1

1

您的 for-in-do 不正确并且放错了位置(在else

 @echo off
 for /f "delims=" %%i in ('type "D:\script\ip.txt" ') do (
 pushd C:\Windows\System32\tools
 plink.exe -l root -pw xxxx root@%%i lsb_release -sr | grep 12.04
  if ERRORLEVEL 1 (
    msg * Sorry, this is NOT a Precise version
      pause
      exit /b
    ) else (
      msg * Cheers, welcome to Precise!
  )
 popd
 )

这是对后续细节的回答——它可能需要一些工作,因为我不知道 plink 是如何工作的或者它处理 Linux 命令的方式。

 @echo off
 for /f "delims=" %%i in ('type "D:\script\ip.txt" ') do (
 pushd C:\Windows\System32\tools
 plink.exe -l root -pw xxxx root@%%i lsb_release -sr | grep 12.04
  REM if 12.04 not found then print message and abort
  if ERRORLEVEL 1 (
    echo Sorry, Ubuntu 12.04 is required.
      pause
      exit /b
  )

plink.exe -l root -pw xxxx root@%%i (dpkg -l | grep libreoffice-core
   REM if libre is found and errorlevel is zero then abort silently
   if not ERRORLEVEL 1 (
      exit /b
  ) else (
   REM if it reaches here then it will install LibreOffice
   plink.exe -l root -pw xxxx root@%%i sudo apt-get install libreoffice
 )
 popd
)
于 2013-06-16T03:03:20.307 回答