Jump to content

How to Modify/Create Another File From a Template Script?


Recommended Posts

We have a handful of servers that needed to be configured.  One of the setup processes is to change the factory default password on it.  There's a script made for that and it's called RIBCL in XML format.  The problem is, I'll have to manually modified the script to have each server's unique password and then excecuting it one by one.

My solution is to either modify and hard coded the password into the RIBCL script or generate a whole new template with the password provided by the user.  My ultimate goal is to have the user enter a series of password, hit run, and the AutoIT script automatically change the RIBCL script below to our standard password and execute .  How would I go about doing so?  I did not find any function that allow me to "write" or create a new template based on the format shown below.  Essentially, my AutoIT script will overwrite this file with the new password over and over again for the number of server provided.

<RIBCL VERSION="2.0">
   <LOGIN USER_LOGIN="adminname" PASSWORD="password">
      <USER_INFO MODE="write">
         <MOD_USER USER_LOGIN="Administrator">
            <PASSWORD value="password"/>
         </MOD_USER>
      </USER_INFO>
   </LOGIN>
</RIBCL>

In the above sample code, I would have to hard code the factory Login_User_Login information since they are randomly generated and provided.  I know this is stupid, writing another script to modify a script!  I've read the RIBCL manual, they suggested to write a batch file for handling multiple hosts.  We all know that AutoIT is 1000x better than batch; hence, I'm reaching out to you folks for help.  :bye:

Edited by dreamzboy
Link to comment
Share on other sites

dzb,

If I am understanding you correctly this might get you started...

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>

local $str = '',$ret, $ts

$str &= '<RIBCL VERSION="2.0">' & @crlf
$str &= '   <LOGIN USER_LOGIN="adminname" PASSWORD="@@password">' & @crlf
$str &= '      <USER_INFO MODE="write">' & @crlf
$str &= '         <MOD_USER USER_LOGIN="Administrator">' & @crlf
$str &= '            <PASSWORD value="@@password"/>' & @crlf
$str &= '         </MOD_USER>' & @crlf
$str &= '      </USER_INFO>' & @crlf
$str &= '   </LOGIN>' & @crlf
$str &= '</RIBCL>'

local $gui010 = guicreate('RIBCL (whatever that is)',600,400)
local $inp010 = guictrlcreateinput('Enter password',20,20,200,20)
local $lbl010 = guictrlcreatelabel('',20,300,560,20,$ss_sunken)
                guictrlsetfont(-1,10,800)
local $btn010 = guictrlcreatebutton('Generate RIBCL File',20,360,560,20)

guisetstate()

while 1
    switch guigetmsg()
        Case $GUI_EVENT_CLOSE
            Exit
        case $btn010
            $ret = filewrite(@scriptdir & '\RIBCL_' & @YEAR & @MON & @MDAY & '_' & @hour & @MIN & @sec,stringreplace($str,'@@password',guictrlread($inp010)))
            if $ret = 1 Then
                guictrlsetdata($lbl010,@scriptdir & '\RIBCL_' & @year & @MON & @MDAY & '_' & @hour & @MIN & @sec & ' generated')
            Else
                guictrlsetdata($lbl010,'File create failed for file = ' & _
                    @scriptdir & '\RIBCL_' & @year & @MON & @MDAY & '_' & @hour & @MIN & @sec)
            endif
    EndSwitch
wend

There is no editing of the input or other error checking...the output file is written to whatever directory you run the script from...

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Oh whow Kylomas.  I didn't expect you write the whole script for me but I truly appreciate the quick response.  :)  It is exactly what I wanted.  I'll build on top of your foundation to make a fully automated process from changing password, network IPs, to naming the servers.

Thank you!  I'll update this post if something comes up in the future.

Link to comment
Share on other sites

I finally got my "version 1.0" to work and now I'm on to making a "version 2.0" by creating a list of inputs.  In the sample scripts above use a single input box asking for a password.  Now, say that I have 5 passwords that I need to generate, how would I process those inputs?  I'm thinking of using GuiCtrlCreateEdit in place of the input box and I know I'll have to use Array.  My question is how do I break up a list of passwords into individual array?  I'm hoping that there's some function that detect "@CRLF" at the end of each input and assign it into an array.  Also, does AutoIT handles dynamic array?

Sample Input:

password1

password2

password3

password4

password5

-Dreamzboy-

Link to comment
Share on other sites

My objective is to break up the list of passwords into individual cell.  I haven't had much luck due to a syntax error when I try to split the string into Array.  I've tried different combination of adding/removing array element from "$string[$i] and $split_Str[$i]" but none worked.  Can anyone point out what I did wrong?

Thanks!

#include <array.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>

Local $split_Str, $i, $password, $generate_btn
Local $string = "This is the @@password."

GUICreate ("Test", 300, 300)

GUICtrlCreateLabel ("1.  Enter iLO default password:", 30, 70, 200, 20)
GUICtrlSetFont (-1, 10)
$password = GUICtrlCreateEdit ("", 30, 90, 200, 70)
$generate_btn = GUICtrlCreateButton ("Generate XML File", 55, 250, 150, 30)
GUICtrlSetFont (-1, 10)

GUISetState ()

Do
   $msg = GUIGetMsg()

    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $generate_btn
            $split_Str = StringSplit (GUICtrlRead ($password), @LF, 3)
            For $i = 0 to UBound ($split_Str - 1)
                $string[$i] = StringReplace ($string[$i], '@@password', $split_Str[$i])
                MsgBox (0, "", $string[$i])
            Next
    EndSelect
Until 0

This is the error:

C:\Users\username\Documents\AutoIT\test2.au3 (28) : ==> Subscript used with non-Array variable.:
$string[$i] = StringReplace ($string[$i], '@@password', $split_Str[$i])
$string^ ERROR
->17:15:38 AutoIt3.exe ended.rc:1
Edited by dreamzboy
Link to comment
Share on other sites

Not sure about what you exactly want, something like this ?

#include <array.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>

Local $split_Str, $i, $password, $generate_btn
Local $string0 = "This is the @@password."
Local $string = "password1" &@crlf& "password2" &@crlf& "password3" &@crlf& "password4" &@crlf& "password5"

GUICreate ("Test", 300, 300)

GUICtrlCreateLabel ("1.  Enter iLO default password:", 30, 70, 200, 20)
GUICtrlSetFont (-1, 10)
$password = GUICtrlCreateEdit ("", 30, 90, 200, 120)
GuiCtrlSetData($password, $string)
$generate_btn = GUICtrlCreateButton ("Generate XML File", 55, 250, 150, 30)
GUICtrlSetFont (-1, 10)

GUISetState ()

Do
   $msg = GUIGetMsg()

    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $generate_btn
            $split_Str = StringSplit (GUICtrlRead ($password), @crlf, 3)
          ;  _ArrayDisplay($split_Str)
            For $i = 0 to UBound($split_Str) - 1
                $res = StringReplace ($string0, '@@password', $split_Str[$i])
                MsgBox (0, "", $res)
            Next
    EndSelect
Until 0

Edited

Sorry I forgot the "replace a word in a string"

Edited by mikell
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...