Sign in to follow this  
Followers 0
TheComputerGuy

Generate Variable from .ini file array

10 posts in this topic

#1 ·  Posted (edited)

Hi, I wonder if someone can point me in the right direction, I'm usually ok finding examples and making scripts work, but this has me stumped.

I've created a small AutoIT program which creates a .ini file, gives it the header [ACTIVE_SESSIONS] I then use a scripted FTP program to connect to various firewalls and Draytek routers to download log data. Sometimes a firewall doesn't need downloading (I.E. One at a seasonal park which is offline in the winter), so in this case, I tell the master script to skip that firewall.

If the script is run, I add a line to the .ini file which enters lines such as - 

 

key0="Firewall ABC"
key1="Firewall XYZ"

 

What I now want to do, is dynamically update the sendmail program that I run at the end of the script, I also fire this from AutoIT using BLAT, so what I need is to be able to dynamically create a variable to use in BLAT.

I need to be able to run through the keys, and add the outputs into a single string.

 

IE, when attaching the PDF logs from the scripts into blat, I need to create something like $attach="Transfer Log =" & $datafromkey0 & ".pdf, Transfer Log =" & datafromkey1 & ".pdf" and so and so forth, and this is where I'm stuck.

In a way, need to create a repeating section that loops through the keys and then dumps it all into one variable.

Edited by TheComputerGuy

Share this post


Link to post
Share on other sites



That bits fine, reading the ini key, but I need to ideally - 

 

Count the number of keys in the file (I can do this with a line count - 1)

 

So, say there are 6 keys, I then need to have a snippet of code populated with the key, then repeated a number of times (according to the line) and then merged into one variable?

 

Share this post


Link to post
Share on other sites

Hi, I wonder if someone can point me in the right direction, I'm usually ok finding examples and making scripts work, but this has me stumped.

I've created a small AutoIT program which creates a .ini file, gives it the header [ACTIVE_SESSIONS] I then use a scripted FTP program to connect to various firewalls and Draytek routers to download log data. Sometimes a firewall doesn't need downloading (I.E. One at a seasonal park which is offline in the winter), so in this case, I tell the master script to skip that firewall.

If the script is run, I add a line to the .ini file which enters lines such as - 

 

key0="Firewall ABC"
key1="Firewall XYZ"

 

What I now want to do, is dynamically update the sendmail program that I run at the end of the script, I also fire this from AutoIT using BLAT, so what I need is to be able to dynamically create a variable to use in BLAT.

I need to be able to run through the keys, and add the outputs into a single string.

 

IE, when attaching the PDF logs from the scripts into blat, I need to create something like $attach="Transfer Log =" & $datafromkey0 & ".pdf, Transfer Log =" & datafromkey1 & ".pdf" and so and so forth, and this is where I'm stuck.

In a way, need to create a repeating section that loops through the keys and then dumps it all into one variable.

Are you saving the PDF's to disk?

 

If so, and they are numbered, then you want to loop through:

Local $i, $iMaxPDFtoAttach = 10

For $i = 1 to $iMaxPDFtoAttach
    $sPathToFileToAttach = @ScriptDir & "/PDF" & $i & ".pdf"
    ConsoleWrite($sPathToFileToAttach)
    ;Do some command here where BLAT attaches it to the email
Next

Alternatively if they are saved to disk with random file names, just use _FileListToArray()

Also, after 3 seconds of googling: "blat attach multiple files"

http://community.tableau.com/message/211808 says: "-attach <file>  : attach binary file(s) to message (filenames comma separated)"

So you'd just loop issuing that command.

 

But who knows.  We need code.

Share this post


Link to post
Share on other sites
$newVal = ""
    ; Check if an error occurred.
    If Not @error Then
        ; Enumerate through the array displaying the keys and their respective values.
        For $i = 1 To $aArray[0][0]
            $NewVal=$NewVal & $aArray[$i][0] & @CRLF & $aArray[$i][1])
        Next
    EndIf

 

Share this post


Link to post
Share on other sites

Sorry, there's more than just attaching the files to blat, maybe if I give a bit of background as to how the system works it'll make more sense.

 

Main FTP Script has a list of firewalls, with a 1 or 0 next to it depending on if it's active.

Main FTP Script calls a secondary FTP script by passing variables into it.

Secondary script calls an autoit program to count the files in the directory.

Script downloads files from the Firewall.

Secondary script calls the autoit program to re-cound the files in the directory and save the difference in a file (named according to firewall name)

Secondary script calls an autoit program to create a .pdf from the .txt logfile generated from the FTP Program.

Once all scripts have run, send an e-mail listing firewall names, along with the amount of files downloaded in that run, and attach all the log files.

 

 

I've basically re-written the whole system, originally it was one large FTP script, that I had to add a new firewall into manually, then edit the AutoIT program manually to add the firewalls etc. By using a standardised FTP script that calls for variables, I want to be able to add a new firewall to be downloaded by simply adding a new line in the main FTP script. So it would be nice to make the sendmail program update the firewalls connected to automatically.

I think I've gotten my head around where I was stuck now though, and I think I can poke at it from here, so thanks :)

 

Share this post


Link to post
Share on other sites

 holy shhh qoute got messed up.

 

Anywho, why not just store the firewall name in the log file, or store it in the filename of the PDF?

Share this post


Link to post
Share on other sites

I think I've got it cracked now :) (Well, I've got a loop that goes through the .ini file and prints a messagebox that says key0 = "Firewall ABC" etc, so should be easy enough to create one line from that now)

Share this post


Link to post
Share on other sites
local $sOutput
$aSection = IniReadSection("test.ini" , "Keys")

for $i = 1 to ubound($aSection) - 1
   $sOutput &= $aSection[$i][0] & "=" & $aSection[$i][1] & @LF
next

msgbox(0, '' , $sOutput)

 


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

This may not be the prettiest way of doing it, and there's more than likely a neater way of doing it, but this works.

Local $iCountLines = _FileCountLines(@ScriptDir & "\active.ini")
      $iCountLinesAmended = $iCountLines - 2 ; Delete two to account for Title, and Blank line at end of .ini file.
Local $i = 0

While $i <= $iCountLinesAmended
    $key = "key" & $i
    Local $system_name = IniRead(@ScriptDir & "\active.ini", "ACTIVE_SESSIONS", $key, "NotFound")
      Local $file = FileOpen("d:\syslog\configuration\Count Files\" & $system_name & " - Count.txt", 0)
      Local $line = FileReadLine($file)
      FileClose($file)

         if $line == 0 Then
            $files_downloaded = "No Files Downloaded."
         ElseIf $line > 1 Then
            $files_downloaded = "Downloaded: " & $line & " file(s)"
         Else
            $files_downloaded = "Downloaded: " & $line & " file"
         EndIf

   $body= $body & "||" & $system_name &":|" & $files_downloaded & "|----------"

   $log = $log & "d:\syslog\configuration\transfer logs\" & $system_name &" - Transfer Log.pdf,"

$i = $i + 1
WEnd

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0