Solved

Batch Scripting

Posted on 2014-04-14
8
289 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 70

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 38

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 38

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 38

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 70

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

Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

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

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
There are many software programs on offer that will claim to magically speed up your computer. The best advice I can give you is to avoid them like the plague, because they will often cause far more problems than they solve. Try some of these "do it…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

739 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