Hola Mundo

#!/usr/bin/perl -w
print "Content-type: text/html \n\n";
print "<!--Esta pagina se ha generado de forma dinamica -->\n";
print "<html>\n";
print "<head>";
print "<title>\"Hola Mundo\"</title>\n";
print "</head>";
print "<body>";
print "<h1>Hola mundo. Este es mi primer CGI en Perl </h1> \n";
print "</body>";
print "</html>\n";

Casiano Rodríguez León
2010-03-22
operation( $readfunc ); DB<1> main::(-:79): if( $operation eq "QUIT" ) { DB<1> main::(-:84): if( $operation eq "EVAL" ) { DB<1> x $operation 0 'EVAL' DB<2> n main::(-:85): my $code = shift @args; DB<2> c Debugged program terminated. Use q to quit or R to restart, use o inhibit_exit to avoid stopping after program termination, h q, h R or h o to get additional info. DB<2> q

Depuración de Programas GRID::Machine con la Opción debug

El programa:

pp2@nereida:~/LGRID_Machine/examples$ cat -n debug1.pl
 1  #!/usr/local/bin/perl -w
 2  use strict;
 3  use GRID::Machine;
 4
 5  my $hostport = shift || $ENV{GRID_REMOTE_MACHINE} || usage();
 6  $hostport =~ m{^([\w.]+)(?::(\d+))?$} or usage();
 7  my $host = $1;
 8  my $port = $2;
 9
10  my $machine = GRID::Machine->new(
11     host => $host,
12     debug => $port,
13     includes => [ qw{SomeFunc} ],
14  );
15
16  my $r =  $machine->eval(q{
17    use vars qw{$a $b $c};
18
19    $a = 4;
20    $b = 2*$a;
21    $c = $a+$b;
22    gprint "machine: ".hostname().": Inside first eval a = $a, b = $b, c = $c\n";
23  });
24
25  $r = $machine->max( 1, 4, 9, 12, 3, 7);
26  show($r);
27
28  $r =  $machine->eval(q{
29    gprint "machine: ".hostname().": Inside second eval\n";
30    gprint "$a $b $c\n";
31    $a+$b+$c;
32  });
33
34  show($r);
35
36  sub usage {
37    warn "Usage:\n$0 host[:port]\n";
38    exit(1);
39  }
40
41  sub show {
42    my $r = shift;
43
44    print $r."result = ".$r->result."\n"
45  }
El fichero someFunc.pm:

pp2@nereida:~/LGRID_Machine/examples$ cat -n SomeFunc.pm
     1  use List::Util qw{max};
     2  use Sys::Hostname;
     3
     4  sub max {
     5    gprint "machine: ".hostname().": Inside sub two(@_)\n";
     6    List::Util::max(@_)
     7  }

Ejecutar nc primero:

casiano@beowulf:~$ netcat -v -l -p 54321
listening on [any] 54321 ...
Ejecutamos el programa:
pp2@nereida:~/LGRID_Machine/examples$ debug1.pl beowulf:54321
Debugging with 'ssh beowulf PERLDB_OPTS="RemotePort=beowulf:54321" perl -d'
Remember to run 'netcat -v -l -p 54321' in beowulf
Ahora tendremos el prompt del depurador en la terminal en la que ejecutamos netcat:
casiano@beowulf:~$ netcat -v -l -p 54321
listening on [any] 54321 ...
connect to [193.145.102.240] from beowulf.pcg.ull.es [193.145.102.240] 60473

Loading DB routines from perl5db.pl version 1.28
Editor support available.

Enter h or `h h' for help, or `man perldebug' for more help.

GRID::Machine::MakeAccessors::(/home/pp2/LGRID_Machine/lib/GRID/Machine/MakeAccessors.pm:33):
33:     1;
  DB<1>

El fichero .perldb permite adaptar la conducta del depurador:

casiano@beowulf:~$ cat -n .perldb
 1  #sub ::beval {
 2  #  print DB::OUT 'b GRID::Machine::EVAL $_[1] =~ m{'.$_[0].'}'
 3  #}
 4
 5  sub ::get_stdout_name {
 6    my $a = `ls rperl*$$*.log`;
 7    chomp($a);
 8    $a;
 9  }
10
11  sub ::sys {
12    my $command = shift;
13
14    $var = `$command`;
15    print DB::OUT $var;
16  }
17
18  #our %alias;
19  $alias{beval} = 's/beval\s+(.+)/b GRID::Machine::EVAL \$_[1] =~ m{$1}/';
20  $alias{bsub}  = 's/bsub\s+(.+)/b GRID::Machine::CALL \$_[1] =~ m{$1}/';
21  $alias{fg}  = 's/fg\s+(\d+)/f eval $1/';
22  $alias{whatf} = 's/whatf\s+(.+)/x SERVER->{stored_procedures}{$1}/';
23  $alias{stdout} = q{s/stdout/::get_stdout_name()/e};
24  $alias{cgs} = 's/cgs\s+(.+)/c GRID::Machine::$1/';
25  $alias{'!!'} = 's/!!\s*(.+)/p `$1`/';
26  $alias{main} = 's/main/c GRID::Machine::main/';
27  $alias{new} = 's/new/c GRID::Machine::new/';

Depurando GRID::Machine en Máquina Remota

pp2@nereida:~/LGRID_Machine/examples$ cat -n netcat3.pl
     1  #!/usr/local/bin/perl -w
     2  use strict;
     3  use GRID::Machine;
     4
     5  my $machine = GRID::Machine->new(
     6     command => q{ssh beowulf 'PERLDB_OPTS="RemotePort=beowulf:12345" perl -d'},
     7     #command => q{ssh nereida perl},
     8  );
     9
    10  print $machine->eval(q{
    11    system('ls');
    12    print %ENV,"\n";
    13  });
    14
    15  __END__

En la máquina remota ejecutamos primero netcat

casiano@beowulf:~$ nc  -v -l beowulf -p 12345
listening on [any] 12345 ...
Ahora arrancamos el programa en la terminal que tenemos en nereida:

pp2@nereida:~/LGRID_Machine/examples$ netcat3.pl

En la terminal de netcat nos aparece el depurador:

connect to [193.145.102.240] from beowulf.pcg.ull.es [193.145.102.240] 48308

Loading DB routines from perl5db.pl version 1.28
Editor support available.

Enter h or `h h' for help, or `man perldebug' for more help.

GRID::Machine::MakeAccessors::(/usr/local/share/perl/5.8.8/GRID/Machine/MakeAccessors.pm:33):
33:     1;
  DB<1> n
GRID::Machine::(/usr/local/share/perl/5.8.8/GRID/Machine/Message.pm:74):
74:     1;
  DB<1> c GRID::Machine::main
GRID::Machine::main(/usr/local/share/perl/5.8.8/GRID/Machine/REMOTE.pm:508):
508:      my $server = shift;
  DB<2> n
GRID::Machine::main(/usr/local/share/perl/5.8.8/GRID/Machine/REMOTE.pm:514):
514:      package main;
  DB<2>
GRID::Machine::main(/usr/local/share/perl/5.8.8/GRID/Machine/REMOTE.pm:515):
515:      while( 1 ) {
  DB<2>
GRID::Machine::main(/usr/local/share/perl/5.8.8/GRID/Machine/REMOTE.pm:516):
516:         my ( $operation, @args ) = $server->read_operation( );
  DB<2>
GRID::Machine::main(/usr/local/share/perl/5.8.8/GRID/Machine/REMOTE.pm:518):
518:         if ($server->can($operation)) {
  DB<2> x ( $operation, @args )
0  'GRID::Machine::EVAL'
1  'use strict;'
2  ARRAY(0x86820fc)
     empty array
  DB<3> c
Debugged program terminated.  Use q to quit or R to restart,
  use o inhibit_exit to avoid stopping after program termination,
  h q, h R or h o to get additional info.
  DB<3> q
casiano@beowulf:~$

Y la salida ocurre en la terminal de netcat:

Algorithm-Knap01DP-0.25
Algorithm-Knap01DP-0.25.tar
..................
HOME/home/casianoSSH_CLIENT193.145.105.252 42097....



Subsecciones
Casiano Rodríguez León
2010-04-20