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

bsharath
bsharath used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Michael EagerConsultant

Commented:
#!/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.  

Commented:
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

Commented:
Forgot to mention, that it's a batch file.
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Author

Commented:
eager which script is this?

renege i get this
ELSE was unexpected at this time.

Commented:
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

Commented:
How are you doing so far?

Author

Commented:
I get this

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

Commented:

@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

Author

Commented:
Where should i store the machinenames?
Whats the file name?
Commented:
pclist.txt

in the format:

pc1
pc2
pc3
@ECHO OFF

SETLOCAL ENABLEDELAYEDEXPANSION

SET LogFile=%~n0.log
SET PClist=pclist.txt
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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial