LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Stuck with a perl script! (https://www.linuxquestions.org/questions/linux-newbie-8/stuck-with-a-perl-script-703250/)

bpeck 02-08-2009 11:55 PM

Stuck with a perl script!
 
- Issues an NSLOOKUP command 50 consecutive times against a local resource(like you own server name) in your own local DNS server and displays the time prior to the first NSLOOKUP command and after the last NSLOOKUP in order to give a rough estimate of performance. Between each command use the IPCONFIG command with the appropriate parameters to flush your DNS resolver cache so that the server is forced to resolve each request.


i was wondering how i may be able to do this with a script!!

j-ray 02-09-2009 02:43 AM

This perl module may come in handy
http://search.cpan.org/~jhi/Time-HiRes-1.9719/HiRes.pm

if you want to execute system commands in perl use
system("command");

good luck,
j

bpeck 02-09-2009 07:15 AM

Yeah that will help a little bit, but i need help with the nslookup and the ipconfig commands in the script..

j-ray 02-09-2009 08:30 AM

sth like that? You have to look for the params of the system programs you need and on the way to calculate the difference from the starting time to end of execution...

but maybe I get you wrong?

see the man pages
man ifconfig
man nslookup

#!/usr/bin/perl

use Time::HiResqw( usleep ualarm gettimeofday tv_interval nanosleep
clock_gettime clock_getres clock_nanosleep clock
stat );

use strict;

my ($i,$start_seconds, $start_microseconds,$end_seconds, $end_microseconds);

($start_seconds, $start_microseconds) = gettimeofday;

for ($i=0;$i<50;$i++){
system("nsklookup -params");
system("ifconfig -params");
}
($end_seconds, $end_microseconds) = gettimeofday;

bpeck 02-09-2009 10:09 AM

ok.....do you do this the same way then or what??

- Issues an NSLOOKUP command 50 consecutive times against the DNS name www.amd.com using your own DNS server to resolve the requests. Again, flush the resolver cache between each command and display the elapsed time before the first and after the last NSLOOKUP command.


i just plug in my ip address for my server in the script (its vmware...192.168.1.100????

thanks for your help...i am kinda new with this Perl scripting

bpeck 02-09-2009 11:08 AM

little bump to see if anyone else knows how to do that..:(

chrism01 02-09-2009 07:29 PM

Show us what you've got so far (code) and what happens when you run it.
http://catb.org/~esr/faqs/smart-questions.html

bpeck 02-10-2009 10:10 AM

i dont have anything now!!!! I gave up and wasnt able to do it. Erased it.....i dont know where to begin.... :(

j-ray 02-11-2009 03:27 AM

You may have to install the HiRes module by typing
sudo cpan Time::HiRes

first
then exchange thi ip given in nslookup command
then run the following script that has to be made executable:


#!/usr/bin/perl

use Time::HiRes qw( usleep ualarm gettimeofday tv_interval nanosleep
clock_gettime clock_getres clock_nanosleep clock );

use strict;

my ($i,$start_seconds, $start_microseconds,$end_seconds, $end_microseconds);

($start_seconds, $start_microseconds) = gettimeofday;

for ($i=0;$i<50;$i++){
system("nslookup 10.49.45.72");
system("ifconfig -a");
}
($end_seconds, $end_microseconds) = gettimeofday;
$start_microseconds= "0.".$start_microseconds;
$end_microseconds= "0.".$end_microseconds;
my $diff = ($end_seconds+$end_microseconds)-($start_seconds+$start_microseconds) ;

print "this took $diff seconds \n";

archtoad6 02-11-2009 07:39 AM

Quote:

Originally Posted by bpeck (Post 3437241)
thanks for your help...i am kinda new with this Perl scripting

Is the point of this to learn Perl, or get a job done? If I were doing this, I'd write a bash script. -- You'll probably end up embedding a series of (bash) shell commands in your Perl anyway, see #9 directly above.

Even if you want to do ultimately do this in Perl, figuring out the manual shell commands would be a good starting point. Why don't you work on those 1st. Show us what you want to do, & we'll try to help you get them into the script of your choice.


All times are GMT -5. The time now is 11:25 PM.