Need write results from 2 seperate files to one log file.

May 30, 2012 at 07:51:01
Specs: Windows 7, 4GB
I am in need of assistance. I have a batch file that runs nightly to restart machines in a specified list (restartmelist.txt) which works flawlessly. What I am looking to do, is have another file (restartmenames.txt) with a list of usernames, so when I look at the results file, I can not only see the results from each machine, but also whose machine it is. The names correlate in order with the machines. So restartmelist.txt looks like this:


And restartmenames.txt looks like this:

Bob Lastname
Bill Lastname
Jason Lastname

Right now, my log-file writes like this:


What I would like to see, is this:

.Machine1 (Bob Lastname)
.Machine2 (Bill Lastname)
.Machine3 (Jason Lastname)

What I don't know how to do, is call that 2nd file to write the log entries, or if it's even possible. Here is what my code currently looks like:


FOR /F "tokens=*" %%A IN ('TIME/T') DO SET Now=%%A

>>c:\scripts\Restartme.log 2>&1 Echo Restarting of machines STARTED on %date% @ %now%
>>c:\scripts\Restartme.log 2>&1 Echo.

set _=c:\scripts\restartmelist.txt
for /f %%i in (
) do (
>>c:\scripts\Restartme.log 2>&1 SHUTDOWN /r /m \\%%i /t %1 /c "This machine is forcibly restarting in %1 seconds!" /f
>>c:\scripts\Restartme.log 2>&1 Echo . %%i

FOR /F "tokens=*" %%B IN ('TIME/T') DO SET NowDone=%%B
>>c:\scripts\Restartme.log 2>&1 Echo.

>>c:\scripts\Restartme.log 2>&1 Echo Restarting of machines COMPLETED on %date% @ %nowdone%
>>c:\scripts\Restartme.log 2>&1 Echo ------------------------------------------------------------------
>>c:\scripts\Restartme.log 2>&1 Echo.

Copy c:\scripts\Restartme.log \\seaapps\apps\logfiles /y

Is this something easy to accomplish!? I appreciate the help from anyone.

--- Charles!

See More: Need write results from 2 seperate files to one log file.

Report •

June 12, 2012 at 22:09:08
As you prob'ly know, batch won't open two files in sync. Maybe your goal can
be achieved in several differnt ways:
1) open the names file and put it into an array
2) use reg query to get the user currently logged onto the machine (which has
some drawbacks: I can't get my remote reg query to work, and the issue of
whether the user is actively logged on or not.)
3) Make a set of files whose names are the machine-designations and whose only
line of data is the username.
4) make a batchfile to build a textfile that joins the two sets of data on one line
The main points to consider:
How many machines?
Reg Query access:
Reg Query is good, because it doesn't have to be maintained, but I don't know
about what happens if user is not logged on - probably will fail. Also the
friggin security crap ("access is denied")
I'm not gonna write any code because I've no clue which approach you want.
I can help with any except the reg query (since mine doesn't work).
If you still need assist, give me a holler and i'll try to help.

Report •

June 13, 2012 at 13:20:31
You can use this to get the systems currently logged in user's first and last name:
@echo off
for /f "skip=1 tokens=2" %%i in (
'qwinsta console /m:%%i'
) do (
for /f "tokens=3-5 delims= " %%a in (
'net user %%i /domain ^| findstr /i /c:"full name"'
) do (
echo %%a %%c

That needs to go in your FOR loop because qwinsta console /m:%%i is the variable in your FOR loop.

Now how you get that inline with your machines proves to be more difficult. You will most likely need to create a temp file containing the machines logs, and another containing the names, then loop through both concatenating each line by line.


Report •

Related Solutions

Ask Question