LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-09-2009, 12:55 AM   #1
bpeck
LQ Newbie
 
Registered: Feb 2009
Posts: 9

Rep: Reputation: 0
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!!
 
Old 02-09-2009, 03:43 AM   #2
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,550

Rep: Reputation: 137Reputation: 137
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
 
Old 02-09-2009, 08:15 AM   #3
bpeck
LQ Newbie
 
Registered: Feb 2009
Posts: 9

Original Poster
Rep: Reputation: 0
Yeah that will help a little bit, but i need help with the nslookup and the ipconfig commands in the script..
 
Old 02-09-2009, 09:30 AM   #4
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,550

Rep: Reputation: 137Reputation: 137
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;

Last edited by j-ray; 02-09-2009 at 09:31 AM.
 
Old 02-09-2009, 11:09 AM   #5
bpeck
LQ Newbie
 
Registered: Feb 2009
Posts: 9

Original Poster
Rep: Reputation: 0
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
 
Old 02-09-2009, 12:08 PM   #6
bpeck
LQ Newbie
 
Registered: Feb 2009
Posts: 9

Original Poster
Rep: Reputation: 0
little bump to see if anyone else knows how to do that..
 
Old 02-09-2009, 08:29 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,411

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
Show us what you've got so far (code) and what happens when you run it.
http://catb.org/~esr/faqs/smart-questions.html
 
Old 02-10-2009, 11:10 AM   #8
bpeck
LQ Newbie
 
Registered: Feb 2009
Posts: 9

Original Poster
Rep: Reputation: 0
i dont have anything now!!!! I gave up and wasnt able to do it. Erased it.....i dont know where to begin....
 
Old 02-11-2009, 04:27 AM   #9
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,550

Rep: Reputation: 137Reputation: 137
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";
 
Old 02-11-2009, 08:39 AM   #10
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
Quote:
Originally Posted by bpeck View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL Updates With Null When Perl Script Run From Shell Script ThisGuyIKnow Programming 6 08-12-2008 10:56 AM
stuck on perl script farkus888 Programming 2 01-02-2008 09:37 AM
NEED HELP IN comment lines PERL Perl script adam_blackice Programming 17 11-07-2007 09:01 AM
Converting a Windows Perl script to a Linux Perl script. rubbercash Programming 2 07-19-2004 11:22 AM
Including methods from a perl script into another perl script gene_gEnie Programming 3 01-31-2002 06:03 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration