Solved

Batch Scripting

Posted on 2014-04-14
8
276 Views
Last Modified: 2014-04-29
Experts,

I am looking for a script to do the following:

I have a file labeled test.txt on multiple computers throughout my network. The file is located at c:\windows\temp\test\test.txt

I have another file at \\FS\data\testcomplete.txt

I nee the output from test.txt from computer A and Computer B to display in testcomplete.txt at \\fs\data\testcomplete.txt

I need it to display in the following format:

COMPUTERA            TRUE
COMPUTERB            TRUE
COMPUTERC            FALSE

I am trying to incorporate this into a labtech script so it must be done using shell commands.

So far I have achieved the following:
COMPUTERA         TRUEComputerB         TRUE
0
Comment
Question by:itguy565
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 25

Expert Comment

by:SStory
ID: 39999108
I'm not sure what the question is. If you are asking how to append to testcomplete.txt
Here's what I'd do.
Map a drive to the UNC share and to each computer's share as needed to get to the data on them.  Assume N: for network, and Z: for each computer.
TYPE Z:\test.txt >> N:testcomplete.txt

This is if the network computer gets all info from the machines. If each local machine somehow appends the info, it would be more difficult as two could try to do it simultaneously.  In that case you could have each local machine map drive N: to the server, write output to a file named after the computer's name, and then on the server have it concat all of those together in a single file. It really depends if this is push or pull in relation to the server.
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 39999265
Looks like you are just collecting the output into a var for all PCs, and only dump the result at the very end. Otherwise you won't see NO line break, because the ECHO command you have to use does not support the suppression of line breaks.

Please show the relevant part of your code (generating that output).
Are you collecting from a single PC, connecting to the other machines?
0
 
LVL 37

Expert Comment

by:Gerwin Jansen
ID: 39999362
Are you looking for some string in the test files? If so, your loop would have to incorporate some test like findstr and based on the result just echo output to your testcomplete file.

Basically like this:

setlocal enabledelayedexpansion
for /f %%c in (computers.txt) do (
 findstr /i string \\%%c\c$\windows\temp\test\test.txt
 if ERRORLEVEL 0 (
   echo %%c TRUE >> testcomplete.txt
 ) else (
   echo %%c FALSE >> testcomplete.txt
 )
)
0
 
LVL 11

Author Comment

by:itguy565
ID: 39999432
The Code I am using is the same as what SStory posted above:
TYPE Z:\test.txt >> N:testcomplete.txt

The problem is this generates the output like this:
COMPUTERA         TRUEComputerB         TRUEComputerC       FALSE

The output I need is
COMPUTERA            TRUE
COMPUTERB            TRUE
COMPUTERC            FALSE

The only thing I haven't been able to figure out is how to create the CR using the type command.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 37

Accepted Solution

by:
Gerwin Jansen earned 334 total points
ID: 39999446
try adding this echo command after your type command:

echo. >> N:testcomplete.txt

(note the attached dot to the echo command)
0
 
LVL 37

Assisted Solution

by:Gerwin Jansen
Gerwin Jansen earned 334 total points
ID: 39999481
The issue is that all your test.txt files do not have a carriage return at the end of the line. Since your files don't have a CR, 'type' is doing just what you're asking.
0
 
LVL 68

Assisted Solution

by:Qlemo
Qlemo earned 166 total points
ID: 39999509
Correct. Type does not append a carriage return/line feed sequence at End Of File. You can do shorter:
  (type Z:\test.txt & echo.) >> N:testcomplete.txt
0
 
LVL 25

Expert Comment

by:SStory
ID: 39999946
As stated above you are missing the newline and echo. should work.
0

Featured Post

Want to promote your upcoming event?

Are you going to an event? Are you going to be exhibiting at a tradeshow? Talking at a conference? Using a promotional banner in your email signature ensures that your organization’s most important contacts stay in the know and can potentially spread the word about the event.

Join & Write a Comment

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
The viewer will learn how to dynamically set the form action using jQuery.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now