Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

Ping one from from within each machine whose name is in the list.

Hi,
Ping one from from within each machine whose name is in the list.

I have a list of machine names in a txt file
I want to go into the machine and ping my exchange server for example to check if the ping works fine from within each client

Regards
Raja
Avatar of Michael Eager
Michael Eager
Flag of United States of America image

#!/bin/bash

while read MACHINE ; do
  ping -c 1 $MACHINE
done < machine_list.txt

You probably want to add checks to see if this works.  
Something like

 
@ECHO OFF

SET LogFile=%~n0.log
SET PClist=%~n0.csv
SET Server=exchangeserver

FOR /F "delims=" %%A in (%PClist%) DO PSEXEC \\%%A PING -n 1 exchangeserver && (ECHO OK %%A>>%LogFile%&ECHO OK %%A) ELSE (ECHO ER %%A>>%LogFile%&ECHO ER %%A)

PAUSE

Open in new window

Forgot to mention, that it's a batch file.
Avatar of bsharath

ASKER

eager which script is this?

renege i get this
ELSE was unexpected at this time.
Maybe I tried to much to do a one liner out of this.

Try this one

@ECHO OFF

SET LogFile=%~n0.log
SET PClist=%~n0.csv
SET Server=exchangeserver

FOR /F "delims=" %%A in (%PClist%) DO (
	PSEXEC \\%%A PING -n 1 %Server% && (
		ECHO OK %%A>>%LogFile%
		ECHO OK %%A
	) ELSE (
		ECHO ER %%A>>%LogFile%
		ECHO ER %%A
	)
)

PAUSE

Open in new window

How are you doing so far?
I get this

C:\>"Ping one from other.bat"
ELSE was unexpected at this time.

@ECHO OFF

SETLOCAL ENABLEDELAYEDEXPANSION

SET LogFile=%~n0.log
SET PClist=%~n0.csv
SET Server=exchangeserver

FOR /F "delims=" %%A in (%PClist%) DO (
	PSEXEC \\%%A PING -n 1 %Server% >NUL
		IF !errorlevel! == 0 (
		ECHO OK %%A>>%LogFile%
		ECHO OK %%A
	) ELSE (
		ECHO ER %%A>>%LogFile%
		ECHO ER %%A
	)
)

PAUSE

Open in new window

Where should i store the machinenames?
Whats the file name?
ASKER CERTIFIED SOLUTION
Avatar of ReneGe
ReneGe
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial