We help IT Professionals succeed at work.

Need to create a batch file to save a list periodically.

Jeremy Bromley
on
Medium Priority
982 Views
Last Modified: 2012-08-13
Hi folks, 500 pointer here :)

Need to create a batch file that creates a Log file for a citrix server farm. I see no way of doing it within Citrix, but am willing to be told whereabouts it is :)

I am trying to log the Load Management Score of a server farm as we are trying to pinpoint what effect is bringing down the servers, but after the event is too late.

Anyway, I can run the following command "QFARM /ZONELOAD" which produces the list, if I add the "> test.txt" pipe it sends that to a text file. I want this to occur every minute or so to build up a picture of how best to set up the server load management on the farm.

Now I would like to either export this to a single file, I can then drag into a spreadsheet (ideal!) OR export to multiple files (one each time) using a filename structure of something like "xxxxLOAD.TXT" where xxxx is a sequential number.

I am imagining this would need to be run as a scheduled task on one of the servers, as I cannot be logged in all the time.

We are using Presentation Manager 4.0, on Windows 2003 Standard servers.
Comment
Watch Question

Qlemo"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015

Commented:
Did you try and have a look at PerfMon if there are counters for your purpose? I suppose there are, and using PerfMon locally or remote would be a much better option.
Hi, there's probably an infinitely better way of doing this, but one way might be be -

@echo off
Date /T >> filename.txt
Time /T >> filename.txt
QFARM /ZONELOAD >> filename.txt

Where "filename.csv" is a set file you want all the data in.

The >> will just append the info on to the end of the file, instead of overwriting it's contents, and the 2 time and date lines just literally print the time and date just prior to running the command. Then just schedule the batch file to run however often you want.

Although I'm not convinced I've understood what result you're after... lol O.o

Pete
Top Expert 2009

Commented:
Put this into a batch file on the Citrix Server.

Schedule the task to run every ??? (minute).

Once you have the data you want to look at in Excel run this code in the comment to make your 1 file.

Set LogFolder=C:\Logs
Set TimeNow=%Time:~0,-3%
Set TimeNow=%Time: =%
Set TimeNow=%Time::=.%
Set DateNow=%Date:~-10%
Set DateNow=%Date:/=%
copy nul ALL_QFARM_%DateNow%_%TimeNow%.csv
for /f %%a in ('dir /od /b "%LogFolder%\QFARM-*.TXT"') do copy "%LogFolder%ALL_QFARM_%DateNow%_%TimeNow%.csv" + "%LogFolder%\%%a" "%LogFolder%\ALL_QFARM_%DateNow%_%TimeNow%.csv"
Set LogFolder=C:\Logs
Set TimeNow=%Time:~0,-3%
Set TimeNow=%Time: =%
Set TimeNow=%Time::=.%
Set DateNow=%Date:~-10%
Set DateNow=%Date:/=%
QFARM /ZONELOAD>%LogFolder%\QFARM_%DateNow%_%TimeNow%.txt"

Open in new window

Jeremy BromleyIT Consultant

Author

Commented:
@AmazingTech - It nearly works :)

The first part (in the code section) creates the log files no problems (the only change I've made is to change the location to H:\Logs - as this is the data folder across the server farm), I have made this change in both bits of code.

However, after running about 20 log files when I run the "compilation code" it just creates a blank file :(

I have attached the code as I have entered it, just for checking.
Set LogFolder=h:\Logs
Set TimeNow=%Time:0,-3%
Set TimeNow=%Time: =%
Set Timenow=%Time::=.%
Set DateNow=%Date:~-10%
Set DateNow=%Date:/=%
QFARM /Zoneload>%LogFolder%\QFARM_%DateNow%_%TimeNow%.txt
 
------------------------------------------------------------------------
 
Set LogFolder=H:\logs
Set TimeNow=%Time:~0,-3%
Set TimeNow=%Time: =%
Set TimeNow=%Time::=.%
Set DateNow=%Date:~-10%
Set DateNow=%Date:/=%
copy nul ALL_QFARM_%DateNow%_%TimeNow%.csv
for /f %%a in ('dir /od /b "%LogFolder%\QFARM-*.TXT"') do copy "%LogFolder%ALL_QFARM_%DateNow%_%TimeNow%.csv" + "%LogFolder%\%%a" "%LogFolder%\ALL_QFARM_%DateNow%_%TimeNow%.csv"

Open in new window

Top Expert 2009

Commented:
Sorry my error here.

OK. This should be correct now.
Set LogFolder=h:\Logs
Set TimeNow=%Time:0,-3%
Set TimeNow=%TimeNow: =%
Set Timenow=%TimeNow::=.%
Set DateNow=%Date:~-10%
Set DateNow=%DateNow:/=%
QFARM /Zoneload>%LogFolder%\QFARM_%DateNow%_%TimeNow%.txt
 
------------------------------------------------------------------------
 
Set LogFolder=H:\logs
Set TimeNow=%Time:~0,-3%
Set TimeNow=%TimeNow: =%
Set TimeNow=%TimeNow::=.%
Set DateNow=%Date:~-10%
Set DateNow=%DateNow:/=%
copy nul "%LogFolder%\ALL_QFARM_%DateNow%_%TimeNow%.csv"
for /f %%a in ('dir /od /b "%LogFolder%\QFARM-*.TXT"') do copy "%LogFolder%\ALL_QFARM_%DateNow%_%TimeNow%.csv" + "%LogFolder%\%%a" "%LogFolder%\ALL_QFARM_%DateNow%_%TimeNow%.csv"
 

Open in new window

Jeremy BromleyIT Consultant

Author

Commented:
Hmm, unfortunately still creating nul file :(
Jeremy BromleyIT Consultant

Author

Commented:
Ah, sussed it now... it was because you had put "QFARM-" instead of "QFARM_" in the code.
Jeremy BromleyIT Consultant

Author

Commented:
One thing that is missing is in the final created file, there is no indication of what the date/time  of the output is.
Top Expert 2009
Commented:
Hmm.. Getting closer I guess is a good thing.
Set LogFolder=h:\Logs
Set TimeNow=%Time:0,-3%
Set TimeNow=%TimeNow: =%
Set Timenow=%TimeNow::=.%
Set DateNow=%Date:~-10%
Set DateNow=%DateNow:/=%
QFARM /Zoneload>%LogFolder%\QFARM_%DateNow%_%TimeNow%.txt
 
------------------------------------------------------------------------
 
Set LogFolder=H:\logs
Set TimeNow=%Time:~0,-3%
Set TimeNow=%TimeNow: =%
Set TimeNow=%TimeNow::=.%
Set DateNow=%Date:~-10%
Set DateNow=%DateNow:/=%
copy nul "%LogFolder%\ALL_QFARM_%DateNow%_%TimeNow%.csv"
for /f %%a in ('dir /od /b "%LogFolder%\QFARM_*.TXT"') do ECHO %%a>>"%LogFolder%\ALL_QFARM_%DateNow%_%TimeNow%.csv" & copy "%LogFolder%\ALL_QFARM_%DateNow%_%TimeNow%.csv" + "%LogFolder%\%%a" "%LogFolder%\ALL_QFARM_%DateNow%_%TimeNow%.csv" & ECHO.>>"%LogFolder%\ALL_QFARM_%DateNow%_%TimeNow%.csv"
 

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Top Expert 2009
Commented:
This is probably a little easier to read and modify.
Set LogFolder=h:\Logs
Set TimeNow=%Time:0,-3%
Set TimeNow=%TimeNow: =%
Set Timenow=%TimeNow::=.%
Set DateNow=%Date:~-10%
Set DateNow=%DateNow:/=%
QFARM /Zoneload>%LogFolder%\QFARM_%DateNow%_%TimeNow%.txt
 
------------------------------------------------------------------------
 
Set LogFolder=H:\logs
Set TimeNow=%Time:~0,-3%
Set TimeNow=%TimeNow: =%
Set TimeNow=%TimeNow::=.%
Set DateNow=%Date:~-10%
Set DateNow=%DateNow:/=%
copy nul "%LogFolder%\ALL_QFARM_%DateNow%_%TimeNow%.csv"
for /f %%a in ('dir /od /b "%LogFolder%\QFARM_*.TXT"') do (
    ECHO ****Start of %%a>>"%LogFolder%\ALL_QFARM_%DateNow%_%TimeNow%.csv"
    copy "%LogFolder%\ALL_QFARM_%DateNow%_%TimeNow%.csv" + "%LogFolder%\%%a" "%LogFolder%\ALL_QFARM_%DateNow%_%TimeNow%.csv"
    ECHO ****End of %%a>>"%LogFolder%\ALL_QFARM_%DateNow%_%TimeNow%.csv"
    ECHO.>>"%LogFolder%\ALL_QFARM_%DateNow%_%TimeNow%.csv"
)

Open in new window

Jeremy BromleyIT Consultant

Author

Commented:
Bloomin' marvellous :)
Jeremy BromleyIT Consultant

Author

Commented:
Many thanks, your help has been invaluable.
Top Expert 2009

Commented:
Thanks for the grade.

I'm glad we got to a working solution.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.