远程检查文件的大小,并得到报告 [英] Remotely check file size and get report

查看:140
本文介绍了远程检查文件的大小,并得到报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该脚本尝试:


  • 从一个txt文件,这是计算机名称列表输入,


  • 检查是否从列表中的计算机上的日志文件大于1000字节,


  • 创建带有日志文件超过1000字节,

  • 这些计算机的名称的TXT报告
  • 创建与计算机的名称所在的文件小于1000字节的另一个TXT报告。


不过,不顺心的事。任何帮助会是很好的。

 关闭@echo
FOR / F令牌= *%%我在(computernames.txt)做致电:checksz %%我
GOTO:EOF:checksz
SETLOCAL
设置文件=\\\\%1 \\ C $ \\ DATA \\ info.log建立
设定分钟= 1000FOR / F有usebackq%% A IN('%文件%')不要设置大小= %%〜ZA如果大小%GTQ%%以上%(
回声。 %1>> logsizemin.txt
)ELSE(
回声。 %1>> logsizemax.txt

大家好,
感谢您的宝贵支持。我祝贺蒙山那些谁构思和建立了这个网站确实做得很好,很有用。
我做了一些修改,你好心建议将其他功能的脚本,但有什么不工作,因为我想..你可以查看我为了隐藏密码在我的批处理使用editv32,其原理是相同的,但你可以检查日志的大小后看到,maxlongsize.txt,以便采取哪些做下一个活动的个人电脑的名称被使用。我希望在活动一开始只有一个身份验证顺序执行上的文件logsizemax.txt所有PC。我注意到,由于某种原因,有时不创建文件logsizemin.txt但我不明白为什么。最大的将是把在另一个文件,例如未在网络上达到了计算机无法访问那些PC,但我完全不知道如何实现它。我希望我有充分的解释。对不起,我英语不好!我想你明白我的用意:)。继批

  @setlocal
关闭@echo
editv32 -p输入用户名:USR
editv32 -m -p输入密码:PWD
FOR / F标记= 1%%我在(computernames.txt)也称:checksz %%我
ENDLOCAL
GOTO:EOF:checksz
SETLOCAL
设置文件=\\\\%1 \\ C $ \\ DATA \\ data.log
设定分钟= 1000
键入NUL> logsizemax.txt
键入NUL> logsizemin.txt
如果不存在的文件%转到%:EOF
FOR / F有usebackq delims =%% A IN('%文件%')DO设置大小= %%〜ZA如果大小%GEQ%%以上%(回声%1>> logsizemax.txt)ELSE(回声%1>> logsizemin.txt)
ENDLOCAL@setlocal
FOR / F标记= 1%%我在(logsizemax.txt)也称:西南%%我
ENDLOCAL
GOTO:EOF:SW
回声。
回声*****************************************
回声* VBS&安培;部署脚本*
回声*****************************************回声。
呼应运行VBS和部署脚本.....PSEXEC \\\\%1%-u USR%-p%PWD%CSCRIPT\\\\代表\\ Reg.vbs
PSEXEC \\\\%1%-u USR%-p%PWD%CMD / C\\\\代表\\ deploy.cmd回声。
回声**************************
回声* EXE运行*
回声**************************回声。
呼应运行exe文件.....PSEXEC -u%USR%-p%PWD%\\\\%1C:\\ Program Files文件\\ TEST.EXE回声。
回声***********************************
回声推出* EXE应用程序*
回声***********************************
回声。
转到结束:结束
出口


解决方案

变化:GTG-> GEQ,不要用引号括变两次,去除导致从回声的空间,一点点清理

  @setlocal
关闭@echo
FOR / F标记= 1%%我在(computernames.txt)也称:checksz %%我
ENDLOCAL
GOTO:EOF:checksz
SETLOCAL
设置文件= \\\\%1 \\ C $ \\ DATA \\ info.log建立
设定分钟= 1000如果不存在的文件%ENDLOCAL%和放大器;&安培; GOTO:EOF
FOR / F有usebackq delims =%% A IN('%文件%')DO设置大小= %%〜ZA如果大小%GEQ%%以上%(回声%1>> logsizemin.txt)ELSE(回声%1>> logsizemax.txt)
ENDLOCAL
GOTO:EOF

编辑:每评论更新从PA和舍甫琴科米 - ENDLOCAL如果文件不存在,并删除\\更新注意

This script tries to:

  • get an input from a txt file, which is a list of computer names,

  • check if a log file on a computer from the list is bigger than 1000 bytes,

  • create a txt report with the names of those computers where the log file is more than 1000 bytes,

  • create another txt report with the names of the computers where the file is less than 1000 bytes.

However, something goes wrong. Any help could be nice.

@echo off
for /f "tokens=*" %%I in (computernames.txt)do call :checksz %%I
goto :eof

:checksz
setlocal
set file="\\%1\c$\data\info.log"
set min=1000

FOR /F "usebackq" %%A IN ('%file%') DO set size=%%~zA

if %size% GTQ %min% (
echo. %1 >>logsizemin.txt
) ELSE (
echo. %1>>logsizemax.txt
)

Hello everyone, thanks for your valuable support. I congratulate whith those who conceived and built this site is really well done and useful. I made some modifications to the script that you have kindly suggested to incorporate other features, but something is not working as I would like .. as you can view I use editv32 in order to hide password in my batch, the principle is the same but as you can see after checking the size of the log, "maxlongsize.txt" is used in order to take the names of the PCs on which do the next activity. I wish that the activities were performed sequentially on all PCs in the file "logsizemax.txt" with only one authentication at the beginning. I noticed that, for some reason sometimes the file "logsizemin.txt" is not created but i don't understand why. The maximum would be to put in another file such as "computer unreachable" those PCs that are not reached on the network but I have absolutely no idea how implement it. I hope I have sufficiently explained. Sorry for bad English! I think you understand my intention :). Following the batch

@setlocal
@echo off
editv32 -p "Enter username:" USR    
editv32 -m -p "Enter password:" PWD
for /f "tokens=1" %%I in (computernames.txt) do call :checksz %%I
endlocal
goto :eof

:checksz
setlocal
set file="\\%1\c$\data\data.log"
set min=1000
type NUL>logsizemax.txt
type NUL>logsizemin.txt
if not exist %file% goto :eof
FOR /F "usebackq delims=" %%A IN ('%file%') DO set size=%%~zA

if %size% GEQ %min% ( echo %1>>logsizemax.txt ) ELSE ( echo %1>>logsizemin.txt )
endlocal

@setlocal
for /f "tokens=1" %%I in (logsizemax.txt) do call :sw %%I
endlocal
goto :eof

:sw
echo.
echo *****************************************
echo *          VBS & Deploy script      *
echo *****************************************

echo.
echo Run VBS and deploy script .....

psexec \\%1 -u %USR% -p %PWD% cscript "\\rep\Reg.vbs"
psexec \\%1 -u %USR% -p %PWD% cmd /c "\\rep\deploy.cmd"

echo.
echo **************************
echo *        EXE Run         *
echo **************************

echo.
echo Running exe .....

psexec -u %USR% -p %PWD% \\%1 "c:\Program Files\test.exe" 

echo.
echo ***********************************
echo *    Exe application launched     *
echo ***********************************
echo.
goto END

:END
exit

解决方案

Changes: GTG->GEQ, don't surround variable with quotes twice, remove leading space from echo, and a little clean up.

@setlocal
@echo off
for /f "tokens=1" %%I in (computernames.txt) do call :checksz %%I
endlocal
goto :eof

:checksz
setlocal
set file=\\%1\c$\data\info.log
set min=1000

if not exist %file% endlocal && goto :eof
FOR /F "usebackq delims=" %%A IN ('%file%') DO set size=%%~zA

if %size% GEQ %min% ( echo %1>>logsizemin.txt ) ELSE ( echo %1>>logsizemax.txt )
endlocal
goto :eof

edit: updated per comments from PA and Andriy M - endlocal if the file doesn't exist, and remove \ update note.

这篇关于远程检查文件的大小,并得到报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆