CA Client Automation

  • 1.  DMS Scripting Help

    Posted Jul 02, 2010 04:03 PM
    I'm trying to write a DMS script that reads one line of a text file, but I'm finding the CA documentation to be inadequate.

    What I want to do is read the second line of a text file, and write that too a .mif file, but all the examples in the documentation assume I want to read every line of the file, so I'm trying to figure out how to read one specific line.

    Thanks.


  • 2.  RE: DMS Scripting Help

    Posted Jul 05, 2010 09:21 AM
    I have never done anything in dmscript, but I became interested in it when I read your question :-)

    ' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    dim objFile as integer
    dim strFileSource as string
    dim iRow as integer
    dim strRow as string
    dim iGetRow as integer

    iRow = 1 'dont touch
    iGetRow = 2 'Edit which row you want.
    strFileSource = "c:\temp\temp.txt"

    objFile=OpenFile(strFileSource,O_READ)

    while Not(Eof(objFile))
    if iRow = iGetRow then
    ReadFile(objFile,strRow)


    Goto End
    end if

    ReadFile(objFile,strRow)
    iRow = iRow + 1
    Wend

    End:

    MessageBox("line " + str(iGetRow) + " in file is: " + strRow)

    ' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


    Or even better, read the file into an array. But I haven't learned that yet


  • 3.  RE: DMS Scripting Help

    Posted Jul 14, 2010 12:14 PM
    Thanks, the script does exactly what I asked for, though I have to admit I thought I that once I saw an example I would be able to take this and adapt it to my needs, but it's going completely over my head. If it's not too much trouble, I'd like to understand it a little better so I can adapt it in to a more complete script. I can see which parts of the script chooses the row you want to read, but I don't understand how it actually works. Do you mind briefly explaining how that works and you were able to figure it out? I have a feeling this might just come down to overall scripting/programming experience. I'm ok with vbs, but that's about it.


  • 4.  RE: DMS Scripting Help

    Posted Jul 19, 2010 04:01 AM
    'the script with more explanations and comments. (sorry my bad english)

    LarsD wrote:



    ' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    ' Declare variables

    dim objFile as integer
    dim strFileSource as string
    dim iRow as integer
    dim strRow as string
    dim iGetRow as integer

    ' set static variables
    ' iRow - row counter
    ' iGetRow - when the counter should stop.
    ' strFileSource - the source to the file to read from.

    iRow = 1 'dont touch
    iGetRow = 2 'Edit which row you want.
    strFileSource = "c:\temp\temp.txt"


    ' Open the file with read rights

    objFile=OpenFile(strFileSource,O_READ)

    while Not(Eof(objFile)) ' Begin read line by line until End Of File or Stop
    if iRow = iGetRow then ' Check if the line is the line you want.
    ReadFile(objFile,strRow) ' If it is the line, then read it and set it to strRow.


    Goto End ' When you found your line, the script ends.
    end if

    ReadFile(objFile,strRow) ' If you havent reached your line yet, just read and continue while-loop.
    iRow = iRow + 1 ' Increment the variable and go on with the while loop.
    Wend

    End: ' end

    MessageBox("line " + str(iGetRow) + " in file is: " + strRow)

    ' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    'you can also do this as a function, maybe it's easier for you to use in your script.


    Function getLine(strFileSource as string, iGetRow as integer) as string

    dim objFile as integer
    dim iRow as integer
    dim strRow as string

    iRow = 1

    objFile=OpenFile(strFileSource,O_READ)

    while Not(Eof(objFile))
    if iRow = iGetRow then
    ReadFile(objFile,strRow)
    Goto End
    end if
    ReadFile(objFile,strRow)
    iRow = iRow + 1
    Wend

    End:

    getLine = strRow

    End Function 'getLine

    ' Then you use it in your script like this
    ' myString = getLine("c:\temp.txt", 2)


  • 5.  Re: RE: DMS Scripting Help

    Posted Jul 31, 2015 02:38 AM

    Hi LarsD,

     

    I was also looking for the same script and luckily found yours. Thank you very much!!

     

    I am able to run the script on the agent and can see that the line am expecting is writing to a .MIF file, but this line is not updating the value under Additional inventory. Can you throw some light on this?

     

    My script

     

    Dim LocalPath As String

    LocalPath = "C:\Program Files\CA\DMS Script Utilities\"

     

    Dim objFile as integer

    Dim strFileSource as string

    Dim iRow as integer

    Dim strRow as string

    Dim iGetRow as integer

     

    iRow = 1

    iGetRow = 2

    strFileSource = "C:\Program Files\CA\Test.txt"

     

    objFile=OpenFile(strFileSource,O_READ)

     

    while Not(Eof(objFile))

    if iRow = iGetRow then

    ReadFile(objFile,strRow)

     

    Goto End

    end if

     

    ReadFile(objFile,strRow)

    iRow = iRow + 1

    Wend

     

    End:

     

    CloseFile(objFile)

     

    CreateMIFFile(localpath+"ReadFromFile.mif","ReadFromFile","","")

    CreateMIFGroup(localpath+"ReadFromFile.mif","Data","","")

    CreateMIFString(localpath+"ReadFromFile.mif","Data","Text",strRow,"From C:\Program Files\CA\Test.txt")

     

     

    Output in MIF file:

     

    Start Component

    Name = "ReadFromFile"

    Description = ""

     

    Start Group

     

      Name = "Data"

      ID = 1

      Class = ""

      Description = ""

     

      Start Attribute

       Name = "Text"

       ID = 1

       Description = "From C:\Program Files\CA\Test.txt"

       Type = String(64)

       Value = "this is testing"

      End Attribute

     

    End Group

     

    End Component

     

     

    Inventory.jpg



  • 6.  Re: DMS Scripting Help

    Posted Jul 31, 2015 07:43 AM

    Comment out or remove the following two lines:

     

     

    Dim LocalPath As String

    LocalPath = "C:\Program Files\CA\DMS Script Utilities\"

     

    These are lines I put in my scripts for local testing. When used in an Asset Job, ‘Localpath’ is a pre-defined constant which is populated automatically with the proper Agent collect directory. The MIF file must be in this directory to be collected as inventory.

     

    Steve McCormick, ITIL

    CA Technologies

    Principal Services Consultant

    Tel: +1-731-676-4223

    Stephen.McCormick@ca.com

    <mailto:Stephen.McCormick@ca.com>



  • 7.  Re: RE: DMS Scripting Help

    Posted Aug 02, 2015 09:56 PM

    Thank you Steve, it worked perfectly.

     

    Regards

    Prasanna



  • 8.  Re: RE: DMS Scripting Help

    Posted Aug 03, 2015 08:02 AM

    Please let us know if this answers you question or if you have followups please post them so we can answer them for you. Thanks in advance Matthew



  • 9.  Re: DMS Scripting Help

    Posted Aug 04, 2015 11:36 AM

    There is a scripting class which was written several years ago and is a little out of date. The class is not offered by the education department currently. I have the original materials and we have considered updating the slides and recording it as a web based class. I would like to gauge interest in such a class before putting in the time and effort to do this. Please respond if you are interested.

     

    Steve McCormick, ITIL

    CA Technologies

    Principal Services Consultant



  • 10.  Re: RE: DMS Scripting Help

    Posted Aug 05, 2015 10:14 PM

    Yes Mathew, this answers my query.

     

    Regards

    Prasanna



  • 11.  Re: DMS Scripting Help

    Posted Aug 04, 2015 11:42 AM

    Thanks for sharing this.