Highlighted
Absent Member.
Absent Member.
3069 views

VuGen Script - Reading in a log file and checking contents

So, We're trying to write a script where the script content is similar to:
--------------
Action()
{

lr_start_transaction("Run Powerterm");

//Run the Powerterm Batch File
system("call Powerterm.bat");

//Stop timing the process

lr_end_transaction("Run Powerterm", LR_AUTO);

// Check for file

fopen c:\log.txt

// Check contents of log.txt
IF Contents = "keyword" then
Transaction = Successful
ELSE
Transaction = Fail

return 0;
}
--------------

Basically, we want to:
1. Start Transaction
2. Call batch file
3. Check for a keyword in a log file
4. Mark as Successful Transation if keyword exists, else mark as fail.

I believe it to be possible, but we're unable to work out the correct syntax.
Does anyone have any similar scripts that have been successful in reading in a logfile to check contents.

Regards,
Lee.
0 Likes
6 Replies
Highlighted
Absent Member.
Absent Member.

Re: VuGen Script - Reading in a log file and checking contents

Hello Lee,

Try this below code and change it accordingly to your requirements:

char *filename="C:\\test.txt";
long filestream;
char *position;
char buffer[1000];
char *search_str = "Prashanth";
int position1=0,count=0;

filestream=fopen(filename,"r+");
while (!feof(filestream)) {

/* Read 1000 bytes while maintaining a running count */
count = fread(buffer, sizeof(char), 1000, filestream);

/* Check for file I/O errors */
if (ferror(filestream)) {

lr_output_message("Error reading file %s", filename);
break;
}

position=(char *)strstr(buffer,search_str);
position1=(int)(position-buffer+1);
lr_output_message("%d",position1);
if(position1>=0)
{
lr_output_message("String Found");
break;
}

}
if(position1<0)
lr_output_message("String Not Found");

Hope this resolves your problem.Let me know if you have any queries on this.

Thanks
Prashanth Thimmavajjala
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: VuGen Script - Reading in a log file and checking contents

Clearly, I've done something wrong, because when I insert your section of code (changing the file name/keyword etc) I get the following errors....

---------
Action.c (24): illegal statement termination
Action.c (24): skipping `char'
Action.c (24): undeclared identifier `filename'
Action.c (24): operands of = have illegal types `int' and `pointer to
char'
Action.c (25): illegal statement termination
Action.c (25): skipping `long'
Action.c (25): undeclared identifier `filestream'
Action.c (26): illegal statement termination
Action.c (26): skipping `char'
Action.c (26): undeclared identifier `position'
Action.c (27): illegal statement termination
Action.c (27): skipping `char'
Action.c (27): undeclared identifier `buffer'
Action.c (27): type error: pointer expected
Action.c (28): illegal statement termination
Action.c (28): skipping `char'
Action.c (28): undeclared identifier `search_str'
Action.c (28): operands of = have illegal types `int' and `pointer to
char'
Action.c (29): illegal statement termination
Action.c (29): skipping `int'
Action.c (29): too many errors
--------

Thanks for responding though! I'll give the points once I've been able to make it work 🙂
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: VuGen Script - Reading in a log file and checking contents

🙂 you seem to be pretty new to writing codes. you seem to have pasted the code as it is after your end_transaction statement. Put the declaration of variables on the top after the action() and then have your commands for the bat file execution and later after the end_transaction you can paste the rest of the code from filestream-fopen(.....) and the rest of the code.

This is still working fine at my end 🙂

Thanks
Prashanth T
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: VuGen Script - Reading in a log file and checking contents

Very new 🙂

I'm normally using VuGen for recording Apps/WebApps etc. I'm not a scripter unfortunately 😞

The only reason we're having to do this is because the version of powerterm embedded currently does not support Kerberos 😞

Therefore, instead of simply recording an ssh connection, we're having to use the latest version of powerterm to run a kerberos script outputting the results to a file that we then read into VuGen.

So, yes I need help! 🙂
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: VuGen Script - Reading in a log file and checking contents

Paste your code here, I suggest the corrections.
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: VuGen Script - Reading in a log file and checking contents

I've currently got nothing more than the original post.

I know what I want to do and believe it to be possible, it's just getting there thats the issue 😞
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.