需要修改脚本以发送从列表中解析的电子邮件

时间:2017-07-27 19:13:31

标签: email batch-file windows-scripting

因此,我们已经开始使用此批处理文件来检查谁正在使用Autodesk许可证以及使用的数量。

以下是剧本的正文:

@ECHO off
echo Running license check utility, please wait...
if not exist "C:\Drawings" mkdir "C:\Drawings
pushd "\\xxx-xxxxxxxxx.com\admin\Support\Software\Autodesk\Licenses\"
lmutil.exe lmstat -s @xxx-xxxxx -a > C:\Drawings\ACDLicU.txt
popd
start /d "C:\Drawings\" ACDLicU.txt

我想修改脚本以解析出ACDLicU.txt文件,以查找打开多个许可证的用户的名称,并将我们的电子邮件域附加到每个用户名。

此外,看起来LMUtil检查我们所有的许可软件,因此只需要在同一部分中多次列出同一用户的情况下解析用户。

下一步是生成一封电子邮件,添加带有附加到收件人列表的域名的用户名列表,有一条消息,例如“你当前正在使用多个许可证,yada yada yada,关闭,其他人正在尝试也工作“然后通过我们的服务器发送该电子邮件。

修改此脚本的原因是,运行它始终是公司范围内电子邮件的前奏,我们很多人都厌倦了获取它们。

这听起来很简单但我在力量的方式上有很多东西需要学习。

我知道自己想要完成什么,但我不确定如何到达那里。

非常感谢您对解决此问题的帮助。

更新

.txt文件输出如下,其中一些必须编辑。有问题的特定许可证是许可证#2。

对于相关的每个许可证,这些行的格式为:用户名,计算机名称(由于我所知的原因连续列出两次),服务器,开始时间

Txt文件输出:

lmutil - Copyright (c) 1989-2009 Acresso Software Inc. All Rights Reserved.
Flexible License Manager status on Thu 7/27/2017 12:35

[Detecting lmgrd processes...]
License server status: 27000@xxx-xxxxx
    License file(s) on xxx-xxxxx: C:\Autodesk\Network License Manager\PAE_07-10-

License server status: 27005@xxx-xxxxx
    License file(s) on xxx-xxxxx: C:\Autodesk\Network License Manager\2018 Autodesk Licenses_Update.lic:

 xxx-xxxxx: license server UP (MASTER) v11.13

Vendor daemon status (on xxx-xxxxx):

  adskflex: UP v11.13
Feature usage info:

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

Users of License #2:  (Total of 72 licenses issued;  Total of 66 licenses in use)

    "License #2" v1.000, vendor: adskflex
    floating license

    Andrew.user xxx-p50s-02 xxx-p50s-02 (v1.000) (xxx-xxxxx/27005 12249), start Thu 7/27 9:08
    Andrew.user xxx-p50s-02 xxx-p50s-02 (v1.000) (xxx-xxxxx/27005 11750), start Thu 7/27 12:03
    Ariel.user xxx-xxx-p184 xxx-xxx-p184 (v1.000) (xxx-xxxxx/27005 9666), start Thu 7/27 12:16
    David.user xxx-xxx-p111 xxx-xxx-p111 (v1.000) (xxx-xxxxx/27005 5352), start Thu 7/27 11:18
    Kevin.user xxx-xxx-P18 xxx-xxx-P18 (v1.000) (xxx-xxxxx/27005 8733), start Thu 7/27 9:04
    Luis.user xxx-p50-02 xxx-p50-02 (v1.000) (xxx-xxxxx/27005 4746), start Thu 7/27 11:32
    Travis.user xxx-xxx-p168 xxx-xxx-p168 (v1.000) (xxx-xxxxx/27005 1135), start Thu 7/27 11:53
    Travis.user xxx-xxx-p168 xxx-xxx-p168 (v1.000) (xxx-xxxxx/27005 15525), start Thu 7/27 10:21
    aj.user xxx-xxx-p23 xxx-xxx-p23 (v1.000) (xxx-xxxxx/27005 15820), start Thu 7/27 9:05
    andrew.user xxx-xxx-p32 xxx-xxx-p32 (v1.000) (xxx-xxxxx/27005 3332), start Thu 7/27 8:44
    anna.user xxx-xxx-p147 xxx-xxx-p147 (v1.000) (xxx-xxxxx/27005 3054), start Thu 7/27 6:56
    aubrey.user xxx-xxx-p169 xxx-xxx-p169 (v1.000) (xxx-xxxxx/27005 5544), start Thu 7/27 11:28
    ben.user xxx-LENX1-18 xxx-LENX1-18 (v1.000) (xxx-xxxxx/27005 4252), start Thu 7/27 11:55
    brent.user xxx-xxx-p164 xxx-xxx-p164 (v1.000) (xxx-xxxxx/27005 9249), start Thu 7/27 9:58
    brett.user xxx-xxx-p185 xxx-xxx-p185 (v1.000) (xxx-xxxxx/27005 13353), start Thu 7/27 7:51
    brian.user xxx-p50-07 xxx-p50-07 (v1.000) (xxx-xxxxx/27005 555), start Thu 7/27 10:29
    charles.user xxx-xxx-p29 xxx-xxx-p29 (v1.000) (xxx-xxxxx/27005 14032), start Thu 7/27 8:58
    charlie.user xxx-xxx-p163 xxx-xxx-p163 (v1.000) (xxx-xxxxx/27005 4353), start Thu 7/27 12:13
    connor.user xxx-xxx-p29 xxx-xxx-p29 (v1.000) (xxx-xxxxx/27005 849), start Thu 7/27 12:34
    craig.user xxx-xxx-p186 xxx-xxx-p186 (v1.000) (xxx-xxxxx/27005 7555), start Thu 7/27 8:57
    dan.user xxx-xxx-p28 xxx-xxx-p28 (v1.000) (xxx-xxxxx/27005 2560), start Thu 7/27 11:27
    dany.user xxx-xxx-p175 xxx-xxx-p175 (v1.000) (xxx-xxxxx/27005 15430), start Thu 7/27 10:54
    david.user xxx-xxx-p187 xxx-xxx-p187 (v1.000) (xxx-xxxxx/27005 12939), start Thu 7/27 9:21
    david.user xxx-w540-03 xxx-w540-03 (v1.000) (xxx-xxxxx/27005 10841), start Thu 7/27 11:32
    douglas.user xxx-xxx-p172 xxx-xxx-p172 (v1.000) (xxx-xxxxx/27005 13638), start Thu 7/27 11:42
    dustin.user xxx-xxx-p10 xxx-xxx-p10 (v1.000) (xxx-xxxxx/27005 9957), start Thu 7/27 9:12
    elise.user xxx-xxx-p37 xxx-xxx-p37 (v1.000) (xxx-xxxxx/27005 1435), start Thu 7/27 10:38
    eric.user xxx-xxx-p110 xxx-xxx-p110 (v1.000) (xxx-xxxxx/27005 14461), start Thu 7/27 9:37
    eugene.user xxx-w540-02 xxx-w540-02 (v1.000) (xxx-xxxxx/27005 12847), start Thu 7/27 12:34
    greg.user xxx-xxx-p30 xxx-xxx-p30 (v1.000) (xxx-xxxxx/27005 5148), start Thu 7/27 7:00
    ian.user xxx-xxx-p04 xxx-xxx-p04 (v1.000) (xxx-xxxxx/27005 2241), start Thu 7/27 11:30
    jarren.user xxx-xxx-p148 xxx-xxx-p148 (v1.000) (xxx-xxxxx/27005 1935), start Thu 7/27 11:24
    jonny.user xxx-P50-04 xxx-P50-04 (v1.000) (xxx-xxxxx/27005 9050), start Thu 7/27 9:06
    josh.user xxx-xxx-p144 xxx-xxx-p144 (v1.000) (xxx-xxxxx/27005 649), start Thu 7/27 8:35
    julia.user xxx-xxx-p190 xxx-xxx-p190 (v1.000) (xxx-xxxxx/27005 10050), start Thu 7/27 12:06
    kara.user xxx-xxx-p03 xxx-xxx-p03 (v1.000) (xxx-xxxxx/27005 14152), start Thu 7/27 12:29
    karina.user xxx-xxx-p81 xxx-xxx-p81 (v1.000) (xxx-xxxxx/27005 11051), start Thu 7/27 9:35
    kasey.user xxx-xxx-p36 xxx-xxx-p36 (v1.000) (xxx-xxxxx/27005 3638), start Thu 7/27 10:04
    khiem.user xxx-w541-04 xxx-w541-04 (v1.000) (xxx-xxxxx/27005 6741), start Thu 7/27 11:49
    mandy.user xxx-xxx-p61 xxx-MONDOPAD (v1.000) (xxx-xxxxx/27005 15232), start Thu 7/27 11:06
    marc.user xxx-yoga260-01 xxx-yoga260-01 (v1.000) (xxx-xxxxx/27005 14639), start Thu 7/27 8:51
    marcus.user xxx-xxx-p189 xxx-xxx-p189 (v1.000) (xxx-xxxxx/27005 11444), start Thu 7/27 9:06
    matthew.user xxx-p50-07 xxx-p50-07 (v1.000) (xxx-xxxxx/27005 10669), start Thu 7/27 10:00
    matthew.user xxx-xxx-p124 xxx-xxx-p124 (v1.000) (xxx-xxxxx/27005 3147), start Thu 7/27 8:12
    melody.user xxx-xxx-p25 xxx-xxx-p25 (v1.000) (xxx-xxxxx/27005 15032), start Thu 7/27 7:48
    meredith.user xxx-xxx-p161 xxx-xxx-p161 (v1.000) (xxx-xxxxx/27005 12548), start Thu 7/27 10:17
    mia.user xxx-xxx-p118 xxx-xxx-p118 (v1.000) (xxx-xxxxx/27005 1729), start Thu 7/27 10:59
    michael.user xxx-xxx-p162 xxx-xxx-p162 (v1.000) (xxx-xxxxx/27005 15935), start Thu 7/27 9:11
    moana.user xxx-lenx1-15 xxx-lenx1-15 (v1.000) (xxx-xxxxx/27005 2732), start Thu 7/27 8:25
    natalie.user xxx-xxx-p146 xxx-xxx-p146 (v1.000) (xxx-xxxxx/27005 5251), start Thu 7/27 8:45
    paul.user xxx-xxx-p42 xxx-xxx-p42 (v1.000) (xxx-xxxxx/27005 6156), start Thu 7/27 10:32
    rasitha.user xxx-xxx-p176 xxx-xxx-p176 (v1.000) (xxx-xxxxx/27005 3740), start Thu 7/27 11:01
    russell.user xxx-xxx-p25 xxx-xxx-p25 (v1.000) (xxx-xxxxx/27005 7255), start Thu 7/27 11:51
    sam.user xxx-p50s-01 xxx-p50s-01 (v1.000) (xxx-xxxxx/27005 14748), start Thu 7/27 11:24
    samuel.user xxx-xxx-p11 xxx-xxx-p11 (v1.000) (xxx-xxxxx/27005 8147), start Thu 7/27 9:06
    sara.user xxx-p50-03 xxx-p50-03 (v1.000) (xxx-xxxxx/27005 10245), start Thu 7/27 10:50
    sara.user xxx-xxx-p171 xxx-xxx-p171 (v1.000) (xxx-xxxxx/27005 8647), start Thu 7/27 11:06
    sean.user xxx-xxx-p23 xxx-xxx-p23 (v1.000) (xxx-xxxxx/27005 153), start Thu 7/27 11:36
    sean.user xxx-xxx-p23 xxx-xxx-p23 (v1.000) (xxx-xxxxx/27005 4949), start Thu 7/27 6:53
    selman.user xxx-xxx-p31 xxx-xxx-p31 (v1.000) (xxx-xxxxx/27005 2662), start Thu 7/27 9:09
    sergey.user xxx-w540-01 xxx-w540-01 (v1.000) (xxx-xxxxx/27005 9736), start Thu 7/27 12:03
    shyla.user xxx-xxx-p136 DESKTOP-G94715Q (v1.000) (xxx-xxxxx/27005 6351), start Thu 7/27 11:07
    shyla.user xxx-xxx-p136 xxx-xxx-p136 (v1.000) (xxx-xxxxx/27005 6035), start Thu 7/27 9:32
    sunghoon.user xxx-xxx-p01 xxx-xxx-p01 (v1.000) (xxx-xxxxx/27005 12033), start Thu 7/27 9:34
    travis.user xxx-xxx-p195 xxx-xxx-p195 (v1.000) (xxx-xxxxx/27005 12360), start Thu 7/27 12:21
    will.user xxx-p50-05 xxx-p50-05 (v1.000) (xxx-xxxxx/27005 1643), start Thu 7/27 8:43

再次更新

1 个答案:

答案 0 :(得分:0)

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET "sourcedir=U:\sourcedir"
SET "destdir=U:\destdir"
SET "filename1=%sourcedir%\q45359218.txt"
SET "outfile=%destdir%\outfile.txt"
(
FOR /f "usebackqtokens=1,2delims=. " %%a IN ("%filename1%") DO (
 REM "%%a" has user-name if "%%b"="user"
 REM if "%%b" is not "user" then not in a data section
 IF "%%b"=="user" (
  IF "%%a"=="!prevuser!" ECHO %%a
  SET "prevuser=%%a"
 ) ELSE (
  SET "prevuser="
 )
)
)>"%outfile%"

GOTO :EOF

您需要更改sourcedirdestdir的设置以适合您的具体情况。

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

您可以使用单引号中的lmutil命令行替换输入文件名,以保存生成物理文件。

读取文件的每一行。对于每一行,使用. Space

进行标记

分隔符(标记1)分隔的行上的第一个字符串分配给%%a,第二个字符串分配给%%b。因此,如果user中有%%b,我们会在%%a中使用使用情况报告行和用户ID。如果我们user没有%%b,那么我们正在阅读华夫饼。

对象是使用相同的用户名报告两个连续的行(因为显示的数据按用户名排序)。这是通过将%%a中的当前名称与!prevuser!中找到的先前名称进行比较来完成的。 setlocal uenabledelayedexpansion调用delayed expansion模式,其中!var!返回变量的运行时值。