Some old Windows batch file tricks

Some very old snippets I used while writing batch files to simplify work.

Parsing date to variables:

rem get name of the day of the week
for /f "tokens=1-4 delims=/ " %%a in ("%date%") do (
Set _wd=%%a
Set _dd=%%c
Set _mm=%%b
Set _yyyy=%%d
)
Set _dt=%_yyyy%-%_mm%%_dd%

Checking which drive specific volume label is mounted on:

echo Checking drives...
for %%a in (d e f g h i j k l m n o p q r s t u v w x y z) do (
echo %%a:
Set _i=%%a
if exist %%a: vol %%a: | find /i "is IPOD" >nul
if not errorlevel 1 goto :ok
)

Creating sequential file backups – log rollover

:mkbkp
if not exist "%~1" goto :eof
Set $i=
:cycle
if exist "%~1.bak%$i%" (
Set /A $i+=1
goto :cycle
)
rem call :out Making backup to: %~1.bak%$i%
echo Making backup to: %~1.bak%$i%
ren "%~1" "%~nx1.bak%$i%"
goto :eof

Writing output to file log and console at the same time:

:out
rem changed logic to fix no-log case
if "%_log%"=="" Set _log=nul
if "%*"=="." (
echo.
echo. >>"%_log%"
goto :eof
)
echo %*
echo %* >>"%_log%"
goto :eof

 

Advertisements

Transaction tracing in complex multi-tier applications

Interesting, it might be worth to do a small wright up on this, but the technique for tracing requests across multiple systems was available for quite some time and is used in various places. But AWS just implemented this on their load balancers only recently: Elastic Load Balancing support for request tracing
This should help in diagnosing various issues with application performance…