Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- rem Version: 1.2
- rem Author: Branislav Vartik
- set loadsamples=60
- set loaddivisor=16
- rem https://stackoverflow.com/questions/6359820/how-to-set-commands-output-as-a-variable-in-a-batch-file
- ::::: ---- defining the assign macro ---- ::::::::
- setlocal DisableDelayedExpansion
- (set LF=^
- %=EMPTY=%
- )
- set ^"\n=^^^%LF%%LF%^%LF%%LF%^^"
- ::set argv=Empty
- set assign=for /L %%n in (1 1 2) do ( %\n%
- if %%n==2 (%\n%
- setlocal enableDelayedExpansion%\n%
- for /F "tokens=1,2 delims=," %%A in ("!argv!") do (%\n%
- for /f "tokens=* delims=" %%# in ('%%~A') do endlocal^&set "%%~B=%%#" %\n%
- ) %\n%
- ) %\n%
- ) ^& set argv=,
- ::::: -------- ::::::::
- setlocal enableextensions enabledelayedexpansion
- rem NOW
- set now=%time:~0,8%
- set now=%now: =0%
- rem USERS
- %assign% qwinsta ^| findstr /r /c:"^...................[^ ]" ^| find /v /c " ID ",users
- set userstring=%users% user
- if %users% leq 9 set userstring= %userstring%
- if not %users% == 1 set userstring=%userstring%s
- rem UPTIME
- %assign% wmic path Win32_PerfFormattedData_PerfOS_System Get SystemUptime ^| findstr /r /c:"[0-9]",uptimes
- set /a uptimes=%uptimes%, uptimed=uptimes / 86400, uptimes %%= 86400, uptimeh=uptimes / 3600, uptimes %%= 3600, uptimem=uptimes / 60, uptimes=uptimes %% 60
- if %uptimeh% leq 9 set uptimeh= %uptimeh%
- if %uptimem% leq 9 set uptimem=0%uptimem%
- set uptimestring=%uptimeh%:%uptimem%
- if %uptimed% == 1 set uptimestring=%uptimed% day, %uptimestring%
- if %uptimed% gtr 1 set uptimestring=%uptimed% days, %uptimestring%
- rem LOAD AVERAGE
- set sum=
- for /f "tokens=2 delims=," %%n in ('typeperf -sc %loadsamples% "\Processor(_Total)\%% Processor Time" ^| findstr /r /c:"\""[0-9]"') do (
- set n=%%n
- set n=!n:"=!
- set /a sum+=n
- )
- set /a load=sum*100/loadsamples/loaddivisor
- set load=00%load%
- set load=%load:~-3,1%.%load:~-2%
- set msg= %now% up %uptimestring%, %userstring%, load average: %load%, %load%, %load%
- echo %msg%
- rem If parameter is given, send to syslog server
- if not [%1] == [] (
- %~dp0logger.exe >nul -l %1 -p user.info -t logger "%msg%"
- rem https://www.adiscon.com/adiscon-tools/an-unix-like-logger-for-windows/
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement