tags:

views:

929

answers:

2

Hello,

I need to have a batch file that copies files (8) in my local directory to either a list of machines on the network (hostname or IP) or have me prompt to enter the next hostname/ip

I'd prefer not to have to run the script over and over again to enter the next hostname/ip

I'll also need to see the output for each system to make sure it connected correctly and copied successfully. Perhaps a "ready to process next?" after each machine?

I don't know how to have a batch file does the equivalent of STDIN, so please forgive the ?STDIN? placeholder

So far, all I have is

net use S: \\?STDIN?\C$ /user:domain\myusername mypassword  

copy %~file01.txt S:\%SystemRoot%\system32 /y
copy %~file02.txt S:\%SystemRoot%\system32 /y
copy %~file03.txt S:\%SystemRoot%\system32 /y
copy %~file04.txt S:\%SystemRoot%\system32 /y
copy %~file05.txt S:\%SystemRoot%\system32 /y
copy %~file06.txt S:\%SystemRoot%\system32 /y
copy %~file07.txt S:\%SystemRoot%\system32 /y
copy %~file08.txt S:\%SystemRoot%\system32 /y

net use :s /delete

do it again
+1  A: 

You can prompt the user for input (and store it into an environment variable) with the set /p command:

set /p HOST=Machine?
net use S: \\%HOST%\C$ ...

You can loop by using a label and jump to it. You should offer a way to exit, though:

:loop
set /p HOST=Machine? (leave blank to exit)
if [%HOST%]==[] goto :EOF
net use S: \\%HOST%\C$ ...
copy ...
...
goto loop

If you don't want to enter each host name individually you can also loop over the arguments to the batch file:

:loop
if [%1]==[] goto :EOF
net use S: \\%1\C$ ...
copy ...
...
shift
goto loop

You can can call it as follows, then:

my_batch machine1 machine2 192.168.12.14 ...

HTH

Joey
A: 

you can use the "if ERRORLEVEL 1" to see if an error occurred in the copy which will allow you to trap for problems with the copy. Along with a "if EXIST" to check that the file is there, though, you may get some files that are zero length.

Though, you may want to investigate Powershell as a more capable tool for the job.

Josh