Solved

Batch Scripting

Posted on 2014-04-14
8
284 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 69

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, EE MVE
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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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
 
LVL 37

Accepted Solution

by:
Gerwin Jansen, EE MVE 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, EE MVE
Gerwin Jansen, EE MVE 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 69

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
How to record audio from input sources to your PC – connected devices, connected preamp to record vinyl discs, streaming media, that play through your audio card: Vista, Windows 7, Windows 8, Windows 8.1 and Windows 10 – both 32 bit & 64.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

770 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