我想结合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地址
答案 0 :(得分: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
)