سؤال

I would like to combine Windows batch script and plink.exe tool (http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html) and run as loop but no luck, below is mine. thanks for your help

@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!
)
)

or it simply to run a Windows batch script as loop.

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

and repeat to next ip address in the ip.txt file

هل كانت مفيدة؟

المحلول

Your for-in-do was incorrect and a misplaced ( after the 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
 )

This is in answer to the followup details - it may need some work as I don't know how plink works or the way it handles Linux commands.

 @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
)
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top