代码之家  ›  专栏  ›  技术社区  ›  user1586957

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

  •  1
  • user1586957  · 技术社区  · 8 年前

    我制作了简单的批处理文件来生成txt文件,谁都在使用许可证。我使用窗口调度程序每隔5分钟进行一次调度。例如

    跑球棒

    @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
    

    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 sri00571 sdi00608

    1 回复  |  直到 8 年前
        1
  •  2
  •   Magoo    8 年前
    @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 包含我测试的数据。

    如果报告中包含除豁免用户名外的其他用户名,则会很有用。

    逐行读取文件,设置 package 如果前2个令牌是 Users of . 在分隔符中包含冒号,以免费删除包名称后的冒号。

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

    首先删除所有 " 从第一行开始,只考虑前13个字符。如果 ---- 这是页脚部分的开始,所以设置 空的 关闭分析。

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

    查找行中的第一个令牌,即用户ID

    lmutil -重定向输出并对其采取行动取决于您)