我已经创建了如下的批处理脚本,我正在使用BALT实用程序在电子邮件中发送此输出。
set length=0
FOR /f "tokens=1 delims=/" %%t IN ("%DATE%") DO SET TT=%%t
FOR /f "tokens=2 delims=/" %%A IN ("%DATE%") DO SET DA=%%A
FOR /f "tokens=3 delims=/" %%B IN ("%DATE%") DO SET DB=%%B
FOR /f "tokens=4 delims=/" %%C IN ("%DATE%") DO SET DC=%%C
for /F "tokens=1 delims=: " %%i in ('time /t') DO SET DD=%%i
for /F "tokens=2 delims=: " %%j in ('time /t') DO SET DE=%%j
for /F "tokens=3 delims=: " %%k in ('time /t') DO SET DF=%%k
C:
cd \siebserver\siebsrvr\BIN
srvrmgr /g mt-wi-sblgatew:2320 /e siebelpro /u SADMIN /p Sadm1npw /i "C:\UJJ\comm.cfg"
ren Status.csv status_old.csv
findstr /v /r /c:["srvrmgr"]["list"] status_old.csv > Status.csv
COPY Status.csv "C:\UJJ\Status.txt
del Status.csv
exit
但输出如下所示:
SV_NAME CC_ALIAS CP_NUM_RUN_TASKS CP_MAX_TASKS CP_ACTV_MTS_PROCS CP_MAX_MTS_PROCS CP_DISP_RUN_STATE
--------- ------------------------- ---------------- ------------ ----------------- ---------------- -----------------
sblprod01 eCommunicationsObjMgr_enu 11 100 4 4 Running
sblprod02 eCommunicationsObjMgr_enu 9 100 4 4 Running
sblprod04 eCommunicationsObjMgr_enu 8 100 4 4 Running
sblprod03 eCommunicationsObjMgr_enu 16 100 4 4 Running
4 rows returned.
SV_NAME CC_ALIAS CP_NUM_RUN_TASKS CP_MAX_TASKS CP_ACTV_MTS_PROCS CP_MAX_MTS_PROCS CP_DISP_RUN_STATE
--------- ------------- ---------------- ------------ ----------------- ---------------- -----------------
sblprod02 EAIObjMgr_enu 75 200 8 8 Running
sblprod03 EAIObjMgr_enu 71 200 8 8 Running
sblprod01 EAIObjMgr_enu 90 200 8 8 Running
sblprod04 EAIObjMgr_enu 73 200 8 8 Running
4 rows returned.
srvrmgr> spool off
spool off
如何以表格格式输出。
答案 0 :(得分:0)
如果您想使用逗号而不是制表符和空格来获取实际的.csv
文件,则此代码应该可以正常工作。还添加了更加可靠的获取日期信息的方法。
@echo off
setlocal enabledelayedexpansion
set length=0
:: Obtaining date information
for /f "tokens=2 delims==+-" %%i in ('wmic os get localdatetime /value ^| findstr "="') do (
set _date=%%i
set YYYY=!_date:~0,4!
set MM=!_date:~4,2!
set DD=!_date:~6,2!
set HH=!_date:~8,2!
set Min=!_date:~10,2!
set Sec=!_date:~12,2!
set Mili=!_date:~-6!
)
cd \siebserver\siebsrvr\BIN
srvrmgr /g mt-wi-sblgatew:2320 /e siebelpro /u SADMIN /p Sadm1npw /i "C:\UJJ\comm.cfg"
ren Status.csv status_old.csv
findstr /v /r /c:["srvrmgr"]["list"] status_old.csv > Status.csv
::Replacing tabs and spaces with commas to obtain actual .csv file
set "output="
if exist status_mod.csv del status_mod.csv
for /f "tokens=* delims=" %%i in ('findstr "_" status.csv') do (
for %%j in (%%i) do (
set "output=!output!%%j,"
)
echo !output:~0,-1! >> status_mod.csv
set "output="
)
copy /y status_mod.csv "C:\UJJ\Status.txt"
del status_mod.csv