Solved

Batch Scripting

Posted on 2014-04-14
8
293 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

Question has a verified solution.

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

In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
This article shows how to use a free utility called 'Parkdale' to easily test the performance and benchmark any Hard Drive(s) installed in your computer. We also look at RAM Disks and their speed comparisons.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

617 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