views:

38

answers:

0

G'day all,

Trying to output the results of the task I'm running in a FOR loop with additional data. In this case, I'm using the FOR loop to read in server names from a text file to setup a scheduled job. I would like to capture the results on each loop and output to a log file but need to insert additional information such as server name and time stamp. Here are some code snippets:

REM - SETUP ENVIRONMENT ------------------------------------------------------------------------------

set source="%~dp0targets.txt"

for /F "tokens=2-4 delims=/ " %%i in ('date /t') do (set datefile=%%k%%i%%j-SNMP_Deploy.log)

for /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c%%a%%b)

for /f "tokens=1-2 delims=/:" %%a in ("%TIME%") do (set mytime=%%a%%b)

REM - PROGRAM VARIABLES ------------------------------------------------------------------------------

set package="%~dp0SNMP_Setup.cmd"

set task=schtasks /create /sc once /tn SNMP_Install /tr %package% /s %%a /u %user% /p %pw% /st %start_time% /sd %start_date%

set log="%~dp0Logs\%datefile%"

REM - SETUP SCHEDULE ON REMOTE SERVERS ---------------------------------------------------------------

for /f "delims=" %%a in ('type %source%') do %task% 1>>%templog1% 2>&1