VMware Cloud Community
vamsiCloud
Contributor
Contributor

Supress echo carriage return?

Hello Experts,

Please help in in supressing the carriage retun of echo.

I want to have the output of  green and red coomads in the same line.

for /f %%i in (%1) do (echo  %%i & sc \\%%i query SSHSecureShell2Server|find "STATE")

The following the the complete script.

REM This script is used to check the status of SSH service on the given list of servers on host.txt
rem usage: c:\>sshcheck host.txt

cls
@echo off

if "%1" == "" goto :EOF

for /f %%i in (%1) do (echo  %%i & sc \\%%i query SSHSecureShell2Server|find "STATE")

goto :EOF


:EOF
echo.

Tags (1)
0 Kudos
4 Replies
RvdNieuwendijk
Leadership
Leadership

I'm not that fluent in commandline scripting to know how you can solve the question you asked. But because you asked your question in the PowerCLI Community, I will give you a PowerCLI answer. I think the next PowerCLI script wil give you the output the commandline script was supposed to give you,  for all your hosts.

Get-VMHost | `
Sort-Object -Property Name | `
Get-VMHostService | Where-Object {$_.Key -like "*SSH*"} | `
Select-Object -Property VMHost,@{N="Service";E={$_.Key}},Running

Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
mattboren
Expert
Expert

Hello, vamsiCloud-

If you wanted to stick with using DOS/cmd.exe for this,  you could do something (somewhat kludgy) like:

REM This script is used to check the status of SSH service on the given list of servers on host.txt
rem usage: c:\>sshcheck host.txt
cls
@echo off
if "%1" == "" goto EOF
setlocal EnableDelayedExpansion
for /f "tokens=*" %%i in (%1) do (
   
set strComputer=%%i
   
for /f "tokens=*" %%s in ('sc.exe \\!strComputer! query SSHSecureShell2Server ^| find "STATE"') do set strState=%%s
   
echo !strComputer! !strState!
   
set strComputer=
   
set strState=
)
endlocal
goto EOF

:EOF
echo.

Had to dig up the oolldd skills there.  Or, you could get the service info in a bit more contemporary fashion using PowerShell like:

$strSvcToFind = "SSHSecureShell2Server"
Get-Content C:\Temp\myMachineNames.txt | select `
    @{n
="ComputerName"; e={$_}},
    @{n
="SvcStatus"; e={
       
$strStatus = (Get-Service -Computer $_ -Name $strSvcToFind -ErrorAction SilentlyContinue).Status
       
if ($strStatus) {$strStatus} else {"svc not found"}}}

How do those do for you?

Message edited 22 Nov 2011 by mattboren:  corrected "goto" statements in batch code -- they had colons in them, which is incorrect

0 Kudos
vamsiCloud
Contributor
Contributor

hello matt,

the cmd script return me the following. i Tried to fix it but no go.

The syntax of the command is incorrect.

Thanks

Vamsi

0 Kudos
mattboren
Expert
Expert

Hello, Vamsi-

Hmm. I cannot reproduce the problem.  I tried on a WinXP client and Win7 -- same successful results.  Though, I did notice that there was a syntax error in the "goto" lines -- they had a colon preceding the label.  The colon should appear at the point that the label is defined, but not along with the label name when using it in a goto call.

I do not think that would cause the issue that you are seeing, though.  To help troubleshoot, comment out (or remove) the "@echo off" line from the batch file, and see what the results are.

0 Kudos