Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Batch Scripting

Posted on 2014-04-14
8
Medium Priority
?
299 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 71

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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 1336 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 1336 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 71

Assisted Solution

by:Qlemo
Qlemo earned 664 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

Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

Question has a verified solution.

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

Configuring Remote Assistance for use with SCCM
Compliance and data security require steps be taken to prevent unauthorized users from copying data.  Here's one method to prevent data theft via USB drives (and writable optical media).
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…
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…

705 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