标题: [文本处理] 批处理如何让输出的信息始终保持在文件第一行(首行)? [打印本页]
作者: merlyn 时间: 2015-10-29 10:51 标题: 批处理如何让输出的信息始终保持在文件第一行(首行)?
一直困扰的问题,如何在使用重定向功能生成的Log日志,最新的保持在第一行。请教有何方法,并保持日志文件的属性如创建时间。- ::
- :: =================================================
- :: Check the physical harddisk on HP DL388 and X64
- :: in case any error or fail
- :: Need to run with HP Array Configuration Utility CLI
- :: =================================================
- ::
- @echo off
-
- "C:\Program Files (x86)\Compaq\Hpacucli\bin\hpacucli.exe" ctrl slot=0 pd all show > zPdfailinfo.log
-
- find "Fail" zPdfailinfo.log
-
- if %ERRORLEVEL% == 0 (goto zNotify)
-
- find "Error" zPdfailinfo.log
-
- if %ERRORLEVEL% == 0 (goto zNotify) else (goto zExit)
-
-
- :zExit
- @ECHO.Running at %date% %time:~0,5% with no error >> zHDcheck.log
- exit /B
-
- :zNotify
- @ECHO.Running at %date% %time:~0,5% with error, pls check >> zHDcheck.log
- zSendmail.vbs
复制代码
zHDcheck.log
Running at 2015-10-25 Sun 9:35 with no error
Running at 2015-10-26 Mon 9:35 with no error
Running at 2015-10-27 Tue 9:35 with no error
Running at 2015-10-28 Wed 9:35 with no error
期望:
zHDcheck.log
Running at 2015-10-28 Wed 9:35 with no error
Running at 2015-10-27 Tue 9:35 with no error
Running at 2015-10-26 Mon 9:35 with no error
Running at 2015-10-25 Sun 9:35 with no error
作者: DAIC 时间: 2015-10-29 12:56
- ::
- :: =================================================
- :: Check the physical harddisk on HP DL388 and X64
- :: in case any error or fail
- :: Need to run with HP Array Configuration Utility CLI
- :: =================================================
- ::
- @echo off
- "C:\Program Files (x86)\Compaq\Hpacucli\bin\hpacucli.exe" ctrl slot=0 pd all show > zPdfailinfo.log
- type zHDcheck.log > zHDcheck_temp.log
- findstr "Fail Error" zPdfailinfo.log && goto zNotify || goto zExit
-
- :zExit
- echo Running at %date% %time:~0,5% with no error > zHDcheck.log
- type zHDcheck_temp.log >> zHDcheck.log
- exit /b
-
- :zNotify
- echo Running at %date% %time:~0,5% with error, pls check > zHDcheck.log
- type zHDcheck_temp.log >> zHDcheck.log
- zSendmail.vbs
复制代码
作者: merlyn 时间: 2015-10-29 14:49
回复 2# DAIC
谢谢楼上回复,提供思路。 type 命令改成 copy,提升了一点效率。- "C:\Program Files (x86)\Compaq\Hpacucli\bin\hpacucli.exe" ctrl slot=0 pd all show > zPdfailinfo.log
-
- copy /y zHDcheck.log zHDcheck_temp.log
-
- findstr "Fail Error" zPdfailinfo.log && goto zNotify || goto zExit
-
- :zExit
- echo Running at %date% %time:~0,5% with no error > zHDcheck.log
- copy /y zHDcheck.log + zHDcheck_temp.log
- del /q "zHDcheck_temp.log"
- exit /b
-
- :zNotify
- echo Running at %date% %time:~0,5% with error, pls check > zHDcheck.log
- copy /y zHDcheck.log + zHDcheck_temp.log
- del /q "zHDcheck_temp.log"
- zSendmail.vbs
复制代码
作者: DAIC 时间: 2015-10-29 17:55
回复 3# merlyn
在你的实际环境里面copy比type快多少?日志文件的体积大概是多少?
请分享一下你的试验数据吧,谢谢。
作者: merlyn 时间: 2015-10-30 11:48
回复 4# DAIC
简单测试了几组数据并验证
LOG文件 35KB 运行时间0.50s左右,COPY比TYPE少0.01
LOG文件 1500KB TYPE 运行时间1.1s左右,COPY 0.8-0.9s
总体测试感觉,LOG文件越大,COPY命令比TYPE效率越高。
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |