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

时间:2017-08-17 07:10:02

标签: batch-file cmd window scheduled-tasks

我制作了简单的批处理文件来生成使用许可证的txt文件。我使用窗口调度程序每隔5分钟安排一次。 for Instance

的run.bat

@echo off
REM See http://stackoverflow.com/q/1642677/1143274
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

1 个答案:

答案 0 :(得分:2)

@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的文件,其中包含我的测试数据。

包含一个包含除免除用户名之外的用户名的报告会很有用。

逐行阅读文件,如果前2个令牌为packageUsers,请设置of。在分隔符中包含冒号,以便在包名后无偿删除冒号。

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

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

任何以4个空格开头的行都是使用中的许可证报告行。忽略任何其他人。

找到该行中的第一个标记,即userID

如果找到的userID是其中一个免除用户,请忽略该行。

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

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