Sign in to follow this  
Followers 0
allen00se

Little help with some scripting

19 posts in this topic

So I am new to AutoIt but from what I can tell so far it should accomplish everything I need. What I want to do is make searching my network login audit logs simple and quick. Right now I have to browse to the server that I want to view, open the audit folder, open the log in notepad, edit>find next> type in user name then see the info.

I have established that I can accomplish all of this via command prompt with these simple commands.

net use v: \\servername\audit

pushd v:

qgrep username *.log

the cmd prompt then returns every line in the audit logs with the username that I searched for.

So now comes the fun part. I want to have a GUI that has a radio button for every office and an empty box for inputting the username. Each radio button will need to be a variable that goes into the script along with the username, that way you just click the office, input the username, hit GO and get the info in return.

Does this sound feasible? IF so where is a good starting point for me to figure out how to do this?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Welcome to AutoIt. :)

Start with the basic tutorials in the help file. You are particularly interested in GuiCreate(), GuiCtrlCreateInput(), GuiCtrlCreateCheckbox(), and GuiCtrlCreateButton().

If you have appropriate rights to connect without additional authentication the drive mapping won't be required. AutoIt can access files directly by UNC paths.

You will want Run() along with StdOutRead() to run your qgrep, or just read the file and parse it yourself with AutoIt functions.

A little time spent with the tutorials and playing with the example scripts in the help file for each function you intend to use will make it all go easier. Also, the AutoIt 1-2-3 tutorial linked in my sig is excellent.

;)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

SO far I pretty much have my GUI built, but now I am looking for tutorials on how to actually use the radio buttons and input buttons. I didnt have much luck with the AutoIt 1-2-3 so far, I guess I will give it another go.

Share this post


Link to post
Share on other sites

Make a short demo script with a small GUI and only one or two buttons that shows your issue. Post it here and you'll get lots of help.

What trouble did you have with the AutoIt 1-2-3 tutorial by Valuater?

;)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Make a short demo script with a small GUI and only one or two buttons that shows your issue. Post it here and you'll get lots of help.

What trouble did you have with the AutoIt 1-2-3 tutorial by Valuater?

;)

I have attached what I have so far. I have the gui set up mainly the way I want, with the main exception being that I don't want the $Edit1 box to populate unless the user selects "Yes" from the msgbox pop up. I haven't found any documentation yet on how to use return values from message boxes. I would imagine there would be an IF statement to the effect of

IF

msgbox return value = 6 Then output data to $Edit1

Else

go back and change values

And on to the main issue, trying to make this thing functional. It works to the extent that it uses the values from the list and the input box to basically print a sentence, now I need to figure out how to make it actually go to the server and search a log file for the username.

My system is setup like so..

\\servername\netlogon\audit.log

Any hints on adding functionality? or a tutorial that might help?

search.au3

Share this post


Link to post
Share on other sites

You will want Run() along with StdOutRead() to run your qgrep, or just read the file and parse it yourself with AutoIt functions.

Can you expand this for me, I have read the help file for StdOutRead () but am not sure where to begin... I will try to look for some info on parsing with AutoIT functions as well.

Share this post


Link to post
Share on other sites

Can you expand this for me, I have read the help file for StdOutRead () but am not sure where to begin... I will try to look for some info on parsing with AutoIT functions as well.

ok so here is my first go at using stdoutread.. not sure where my problem is but when I run the script i get no errors and nothing happens and eventually I just ctrl+break. If I pull the $STDOUT_CHILD out of the run command then the cmd window pops up and closes as expected.

Any ideas?

#include <Constants.au3>

local $loginfo = Run("cmd.exe", $STDOUT_CHILD)

local $logdata

WinWaitActive("C:\Windows\system32\cmd.exe")

send ("net use v: \\saguaro\audit /persistent:no & pushd v: & qgrep kallen *.log{enter}")

send ("exit{enter}")

While 1

$logdata = StdoutRead($loginfo)

If @error Then ExitLoop

MsgBox(0, "STDOUT read:", $logdata)

;GUICtrlSetData($Edit1, $username & "'s login info:" & $logdata)

Wend

While 1

$logdata = StderrRead($loginfo)

If @error Then ExitLoop

MsgBox(0, "STDERR read:", $logdata)

;GUICtrlSetData($Edit1, $username & "'s login info:" & $logdata)

Wend

Share this post


Link to post
Share on other sites

Check the helpfile for the proper syntax!

Any chance you could be more specific? I have been living in that help file and I actually tried a few different options but got the same result... It really sucks that I get no error because I really can't narrow it down.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Any chance you could be more specific? I have been living in that help file and I actually tried a few different options but got the same result... It really sucks that I get no error because I really can't narrow it down.

You know it surprises me that you say you actually looked at the helpfile, because when assuming I understand what you want to accomplish, the example in the helpfile for StdOutRead() is exactly what you want.

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

You know it surprises me that you say you actually looked at the helpfile, because when assuming I understand what you want to accomplish, the example in the helpfile for StdOutRead() is exactly what you want.

Jos

Ok well I was looking at it all wrong... I have it mainly figured out now but one thing does have me stumped...

Here is where I am at currently:

#include <Constants.au3>

Local $foo = Run(@ComSpec & " /c ipconfig", @SystemDir, @SW_HIDE, $STDOUT_CHILD)

Local $line

While 1

$line = StdoutRead($foo)

If @error Then ExitLoop

MsgBox(0, "STDOUT read:", $line)

Wend

MsgBox(0, "Debug", "exiting")

The thing that I can't figure out is I get two message boxes, first on that pops up is blank, after I close it a second one pops up with the ipconfig info. Why is there a blank box to begin with?

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Probably because the IPConfig initially outputs an empty line?

Just concatenate all output and display the total output in your MsgBox() when all output is read.

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Probably because the IPConfig initially outputs an empty line?

Just concatenate all output and display the total output in your MsgBox() when all output is read.

Jos

Jos,

Im not sure how I would go about concatenating all output. I do agree with you on whats happening though, just not sure how to fix it.

Share this post


Link to post
Share on other sites

something like this ? :

#Include <Constants.au3>

Local $foo = Run(@ComSpec & " /c ipconfig", @SystemDir, @SW_HIDE, $STDOUT_CHILD)
Local $line
While 1
    $line &= StdoutRead($foo)
    If @error Then ExitLoop
WEnd
MsgBox(0, "STDOUT read:", $line)

Jos ;)


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

something like this ? :

#Include <Constants.au3>

Local $foo = Run(@ComSpec & " /c ipconfig", @SystemDir, @SW_HIDE, $STDOUT_CHILD)
Local $line
While 1
    $line &= StdoutRead($foo)
    If @error Then ExitLoop
WEnd
MsgBox(0, "STDOUT read:", $line)

Jos ;)

Jos,

Thanks for all your help, I got the whole script done and it works like a charm thanks to you!

Share this post


Link to post
Share on other sites

Ok, so on to the next level... Currently my script searches the logs and returns the lines that contain the specified username.

kallen's login info:

LOGON kallen TO 88304157MJVWZ20 Ver 6.1 on 2010/10/04 at 15:31:48 IP 10.122.100. 9 Logon Server=\\SAGUARO

LOGOFF kallen FROM 88304157MJVWZ20 Ver 6.1 on 2010/10/04 at 16:17:05 IP 10.122.100. 9

LOGON kallen TO 88307359MJLGE31 Ver 6.1 on 2010/10/05 at 17:11:12 IP 10.122.100. 32 Logon Server=\\SAGUARO

LOGOFF kallen FROM 88307359MJLGE31 Ver 6.1 on 2010/10/05 at 17:13:46 IP 10.122.100. 32

LOGON kallen TO 88307359MJLGE31 Ver 6.1 on 2010/10/06 at 11:52:57 IP 10.122.100. 32 Logon Server=\\SAGUARO

LOGOFF kallen FROM 88307359MJLGE31 Ver 6.1 on 2010/10/06 at 12:01:17 IP 10.122.100. 32

LOGON kallen TO 88307359MJLGE31 Ver 6.1 on 2010/10/06 at 12:02:51 IP 10.122.100. 32 Logon Server=\\SAGUARO

LOGOFF kallen FROM 88307359MJLGE31 Ver 6.1 on 2010/10/06 at 12:05:18 IP 10.122.100. 32

Now this is nice... but I would really like to be able to ditch some of the unimportant info to clean it up. Would it be possible to filter this info down to something like this?

LOGON kallen TO 88304157MJVWZ20 10.122.100. 9

LOGOFF kallen FROM 88304157MJVWZ20 10.122.100. 9

LOGON kallen TO 88307359MJLGE31 10.122.100. 32

LOGOFF kallen FROM 88307359MJLGE31 10.122.100. 32

LOGON kallen TO 88307359MJLGE31 10.122.100. 32

LOGOFF kallen FROM 88307359MJLGE31 10.122.100. 32

LOGON kallen TO 88307359MJLGE31 10.122.100. 32

LOGOFF kallen FROM 88307359MJLGE31 10.122.100. 32

Or even if for starters I could just return the most recent PC name (always the bottom line) either logged on or off from.

88307359MJLGE31

What would be required? Can you give me some hints to google?

Thanks,

Krys

Share this post


Link to post
Share on other sites

I think I have found a way to do this filtering using For and tokens and delims... I will post back what I come up with.

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

I think I have found a way to do this filtering using For and tokens and delims... I will post back what I come up with.

I partially have this thing figured out. I can run the command that I as a batch file and it works, now I just have to figure out how to get it to work in AutoIT.

here is the batch file I created that works:

FOR /F "tokens=2,3,4 delims= " %%A IN ('findstr kallen *.log') DO IF "%%A" =="kallen" SET PC_NAME="%%C"

set PC_NAME

and that takes this text that is in a .log file:

LOGOFF kallen FROM 88307359MJLGE31 Ver 6.1 on 2010/10/06 at 12:05:18 IP 10.122.100. 32

To this:

PC_NAME="88307359MJLGE31"

Which is great, except for the fact that I can't get it to translate into AutoIT. I am guessing it has something to do with the single quotes needed inside the parenthesis. Here is how I am trying to run it in autoIT (i had to use the variable $parainfo because the single quotes screwed up my line):

$parainfo = "('findstr kallen *.log')"

Run(@ComSpec & ' /c pushd v: & FOR /F "tokens=2,3,4 delims= " %%A IN ' & $parainfo & 'DO IF "%%A" =="kallen" SET PC_NAME="%%C" & pause', "", @SW_MAXIMIZE)

I get no output, just a flash of the cmd prompt.

So I am stumped now, hopefully its just syntax somewhere, lemme know if you have any ideas.

Edited by allen00se

Share this post


Link to post
Share on other sites

Got it!!

apparently the variable %%A and %%B works in a batch file, but from the cmd line its %A and %B

so thats fixed.

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