Highlighted
New Member.
2372 views

Modify host entries from Vugen Script

Hi,

 

I have a situation where we have 15 Web Servers and we would like to validate those 15 web servers before we start any load test. In order to do this, we will map the IP address of the Web Server to that of the domain name in the host file of our system and then perform few actions on the application after logging in. This has to be repeated 15 times as we have 15 web servers. The othe problem is we can't directly navigate to the application using IP address of the web server as it would redirect to the domain name as soon as we hit the application. So, is there any way that I can script using VuGen and perform few actions on the application and then modify the host file to the next Web Server and repeat the same actions? I would like the VuGen script to change the host file entry before the next iteration starts. Is this possible? If so, please provide the solution for this. Your help is highly appreciated!

 

Thanks,

Ganesh

0 Likes
3 Replies
Highlighted
Absent Member.
Absent Member.

Re: Modify host entries from Vugen Script

The navigation can be done by a web script I guess. To edit the hosts file, you can use C file handling functions and commands and edit the contents of the file through your script. Hope this helps.

 

Thanks

Prashanth Thimmavajjala

0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Modify host entries from Vugen Script

Here is some old code i have that may be of use to you.

 

long file_stream;
char command[1024];
char *windir;
char *filename ="C:\\WINDOWS\\system32\\drivers\\etc\\hosts";


CommandLine()
{
     windir = (char *)getenv("WINDIR"); // get the windows directory environment variable from the system this runs on.

 lr_output_message("%s", windir);
 //Make a copy of the original host file.
  sprintf (command, "copy %s\\system32\\drivers\\etc\\hosts %s\\system32\\drivers\\etc\\oldhostfile /y", windir, windir);
  system(command);

  // Open file and add the line to the end of it.
  if ((file_stream = fopen(filename, "a+")))
 {
  fprintf(file_stream,"156.77.100.152 www.mysite.com");
  fclose(file_stream);
        }
 else
 {
 lr_output_message("File could not be opened");
 }

     // Copy back the original host file.
 sprintf (command, "copy %s\\system32\\drivers\\etc\\oldhostfile %s\\system32\\drivers\\etc\\hosts /y", windir, windir);
    system(command);

 // Del the copy we made at the beginning.
 sprintf (command, "del %s\\system32\\drivers\\etc\\jgl", windir);
    system(command);

 return 0;
}

0 Likes
Highlighted
Frequent Contributor.. Frequent Contributor..
Frequent Contributor..

Re: Modify host entries from Vugen Script

I'm having a similar issue. I'm not sure I want to impact my host file, though. We have a web based site that also will redirect a server directed call back through the load balancer. I was wondering if perhaps the VuGen script had a function that could be called to override the host entry from DNS? I could write one script per server, and just have to update the IP for the new server. Can this be done?

Thanks,

Stephen

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.