计划任务并报告其他用户是否正在使用许可证

Scheduling task and report if Other user is using licences

我制作了简单的批处理文件来生成正在使用许可证的 txt 文件。我使用 window 调度程序每 5 分钟安排一次。例如

run.bat

@echo off
REM See 
FOR /f %%a IN ('WMIC OS GET LocalDateTime ^| FIND "."') DO SET DTS=%%a
SET DateTime=%DTS:~0,4%-%DTS:~4,2%-%DTS:~6,2%_%DTS:~8,2%-%DTS:~10,2%-%DTS:~12,2%
echo %DateTime%

lmutil lmstat -a -c @hc-ukr-mu-ap-23 >%DateTime%.txt

2017-08-17_12-06-18.txt

lmutil - Copyright (c) 1989-2017 Flexera Software LLC. All Rights Reserved.
Flexible License Manager status on Thu 8/17/2017 12:06

[Detecting lmgrd processes...]
License server status: 27000@servername
    License file(s) on servername: C:\Program Files (x86)\ArcGIS\License10.5\bin\service.txt:

servername: license server UP v11.14.1

Vendor daemon status (on servername):

    ARCGIS: UP v11.14.1
Feature usage info:

Users of ACT:  (Total of 1 license issued;  Total of 0 licenses in use)

Users of ARC/INFO:  (Total of 4 licenses issued;  Total of 4 licenses in use)

  "ARC/INFO" v10.1, vendor: ARCGIS, expiry: permanent(no expiration date)
  floating license

    adi00516 C8QBXFY1 wy30_lAB;l|`dgw,' (v10.1) (servername/27000 2766), start Wed 8/16 11:58
    uvi00887 CBPMGBG2 w$<Dbk.0)n1tx{/JF (v10.1) (servername/27000 172), start Thu 8/17 9:40
    sri00571 CDT7VD02 w&B4alwyrVtX\_o*  (v10.1) (servername/27000 1341), start Thu 8/17 10:00
    sdi00608 C5VWHQ12 wv5Gf~+-&iy]adu)& (v10.1) (servername/27000 1543), start Thu 8/17 11:32

Users of ArcStorm:  (Total of 4 licenses issued;  Total of 0 licenses in use)

Users of ArcStormEnable:  (Total of 4 licenses issued;  Total of 0 licenses in use)

Users of Editor:  (Total of 5 licenses issued;  Total of 1 license in use)

  "Editor" v10.1, vendor: ARCGIS, expiry: permanent(no expiration date)
  floating license

    adi00516 C8QBXFY1 ww9-Tcqsl>N269I]X (v10.1) (servername/27000 807), start Thu 8/17 11:44

Users of GeoStats:  (Total of 1 license issued;  Total of 0 licenses in use)

Users of Grid:  (Total of 3 licenses issued;  Total of 1 license in use)

  "Grid" v10.1, vendor: ARCGIS, expiry: permanent(no expiration date)
  floating license

    adi00516 C8QBXFY1 wy30_lAB;l|`dgw,' (v10.1) (servername/27000 4201), start Wed 8/16 11:59

Users of MrSID:  (Total of 4 licenses issued;  Total of 0 licenses in use)

Users of Network:  (Total of 1 license issued;  Total of 0 licenses in use)

Users of Plotting:  (Total of 4 licenses issued;  Total of 0 licenses in use)

Users of Publisher:  (Total of 1 license issued;  Total of 1 license in use)

  "Publisher" v10.1, vendor: ARCGIS, expiry: permanent(no expiration date)
  floating license

    sri00571 CDT7VD02 w&B4alwyrVtX\_o*  (v10.1) (servername/27000 1289), start Thu 8/17 10:01

Users of TIFFLZW:  (Total of 4 licenses issued;  Total of 0 licenses in use)

Users of TIN:  (Total of 3 licenses issued;  Total of 2 licenses in use)

  "TIN" v10.1, vendor: ARCGIS, expiry: permanent(no expiration date)
  floating license

    uvi00887 CBPMGBG2 w$<Dbk.0)n1tx{/JF (v10.1) (servername/27000 1929), start Thu 8/17 9:40
    sdi00608 C5VWHQ12 wv5Gf~+-&iy]adu)& (v10.1) (servername/27000 3663), start Thu 8/17 11:32

Users of Viewer:  (Total of 3 licenses issued;  Total of 0 licenses in use)



----------------------------------------------------------------------------
License server status: 27009@servername
    License file(s) on servername: licenses\geoslope\configure.lic:

servername: license server UP v11.14.1

Vendor daemon status (on servername):

我想检查除此列表之外是否还有人在使用该许可证?它每 5 分钟生成一次上述文件。

adi00516 uvi00887 sri00571 sdi00608

@ECHO Off
SETLOCAL
SET "sourcedir=U:\sourcedir"
SET "filename1=%sourcedir%\q45728670.txt"

FOR /f "usebackqdelims=" %%a IN ("%filename1%") DO (
 FOR /f "tokens=1-3 delims=: " %%A IN ("%%a") DO IF "%%A%%B"=="Usersof" (
  SET "package=%%C"
 ) ELSE (
  SET "line=%%a"
  IF DEFINED package CALL :analyse
 )
)
GOTO :EOF

:analyse
:: remove any `"` from the line 
:: and interested only in the first 13 characters
SET "line=%line:"=%"
SET "line=%line:~0,13%"
:: turn analysis off if end-of-report-body
IF "%line:~0,4%" equ "----" set "package="&GOTO :EOF 
:: interested only in lines starting with 4 spaces
IF "%line:~0,4%" neq "    " GOTO :EOF 
:: first token in exemption-list
FOR /f %%A IN ("%line%") DO SET "luser=%%A"
FOR %%E IN (
 adi00516 uvi00887 sri00571 sdi00608
 ) DO IF %luser%==%%E GOTO :EOF 

ECHO User %luser% is using %package%

GOTO :eof

您需要更改 sourcedir 的设置以适合您的情况。

我使用了一个名为 q45728670.txt 的文件,其中包含您的数据用于我的测试。

包含一份包含豁免用户名以外的用户名的报告会很有用。

读取文件 line-by-line,如果前 2 个标记是 Usersof,则设置 package。在分隔符中包含冒号,以无偿删除包名称后的冒号。

分析所有其他行,一旦检测到包名称(忽略报告的 header 部分。)

首先从行中删除所有",只考虑前13个字符。如果 前 4 个字符是 ---- 然后这是页脚部分的开始,因此将 package 设置为 以关闭分析。

任何以 4 个空格开始的行都是 licence-in-use 报告行。忽略任何其他人。

找到行中的第一个标记,即用户ID

如果找到的用户 ID 是豁免用户之一,请忽略该行。

否则,报告找到的包和用户。

(您只需要更改文件名并在 运行 lmutil 之后包含此例程 - 重定向输出并对其进行操作由您决定)