lordoftheclip
lordoftheclip

Reputation: 11

Remotely check file size and get report

This script tries to:

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

Upvotes: 1

Views: 1492

Answers (2)

Jeremy Murray
Jeremy Murray

Reputation: 796

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.

Upvotes: 1

PA.
PA.

Reputation: 29349

You can avoid using environment variables and using the second FOR alltogether. Try this simpler version of your bat, with a more generic :checksz routine.

@echo off
for /f "tokens=*" %%a in (computernames.txt) do (
  call :checksz "\\%%a\c$\data\info.log" 1000 "%%a"
)
goto :eof

:checksz
if %~z1 GTR %2 (
echo %~3 >> logsizemin.txt
) ELSE (
echo %~3 >> logsizemax.txt
)
goto :eof

see HELP CALL for more information.

Upvotes: 1

Related Questions