Professional Web Applications Themes

cannot call a process via telnet - PERL Beginners

Hello together, I have certain problem with the Net::Telnet () -package. I try to call a program on a remote server over the telnet. ( I cannot use SSH in this case! ) my $command = "cd /home/chris/servlist $t = new Net::Telnet (Timeout => 15,Prompt => '/\[datagate\]\/KOMM\/datagate>/') or die "cannot call telnet!\n"; $t->open ("komm") or die "cannot establish a connection!\n"; $rueck = $t->login ($username, $passwd) or die "login failed!\n"; .... so far it works. But now I try this: ra = $t->print ( $command_1 ) or die "cannot change dir !\n"; $rs = $t->print ( "./komm-test.pl" ) or die "cannot ...

  1. #1

    Default cannot call a process via telnet

    Hello together,
    I have certain problem with the Net::Telnet () -package.
    I try to call a program on a remote server over the telnet. ( I cannot use
    SSH in this case! )

    my $command = "cd /home/chris/servlist
    $t = new Net::Telnet (Timeout => 15,Prompt =>
    '/\[datagate\]\/KOMM\/datagate>/') or die "cannot call telnet!\n";


    $t->open ("komm") or die "cannot establish a connection!\n";
    $rueck = $t->login ($username, $passwd) or die "login failed!\n";

    .... so far it works.
    But now I try this:

    ra = $t->print ( $command_1 ) or die "cannot change dir !\n";
    $rs = $t->print ( "./komm-test.pl" ) or die "cannot start script!\n";
    And this doesn't work. I neither crashes down nor gives me a error-message!
    The return value $rs is 1 !!!!
    .....
    $t->close ();

    What did I wrong?

    Gruss Christian

    P.S by the way, I can see that the script doesn't start because "komm-test.pl
    creates a file if it starts!


    --
    Christian Stalp

    Institut für Medizinische Biometrie, Epidemiologie und Informatik (IMBEI)
    Obere Zahlbacher Straße 69
    55131 Mainz
    Tel.: 06131/ 17-6852

    E-Mail: uni-mainz.de
    Internet: www.imbei.de
    Christian Guest

  2. #2

    Default Re: cannot call a process via telnet

    > Hello together, 
    use 

    What you have shown won't compile. Are you using 'strict' and
    'warnings'? If not you need to be.
     

    No closing quote or semi-colon in the above.
     

    You aren't declaring the scope of $t.
     

    You aren't declaring ra. You appear to try to be running $command_1
    instead of $command. Turn on 'strict' and 'warnings'.
     
    error-message! 
    "komm-test.pl 

    Not really a good way to tell.

    http://danconia.org
    Wiggins Guest

  3. #3

    Default Re: cannot call a process via telnet

     

    Its not the whole file. I paste some parts of the script into the mail
    ,renamed the variables in english ... but I also doesn't use strict. Maybe
    this gives me a hint of whats going wrong.

    Gruss Christian


    --
    Christian Stalp

    Institut für Medizinische Biometrie, Epidemiologie und Informatik (IMBEI)
    Obere Zahlbacher Straße 69
    55131 Mainz
    Tel.: 06131/ 17-6852

    E-Mail: uni-mainz.de
    Internet: www.imbei.de
    Christian Guest

  4. #4

    Default Re: cannot call a process via telnet

    As I expact, I just fixed the scope errors but the problem remains.
    This is it:

    sub telnet_access
    {
    my $username = $main::username;
    my $passwd = $main::passwd;
    my $command_1 = "cd /home/chris/servlist/";
    my ra;
    my $rs;
    my $t;

    $t = new Net::Telnet (Timeout => 15,Prompt => '/\[datagate\]\/KOMM\/datagate 

    $t->open ("komm") or die "cannot establish a connection!\n";
    $rs = $t->login ($username, $passwd) or die "login failed\n";


    ra = $t->print ( $command_1 ) or die "cannot change dir!\n";
    $rs = $t->print ( "./komm-test.pl" ) or die "cannot start script!\n";
    print "$rs\n";

    $t->close ();
    }

    It runs without any errors but also without purpose, because it doesn't start
    the script on the remote host. :-\

    Gruss Christian


    --
    Christian Stalp

    Institut für Medizinische Biometrie, Epidemiologie und Informatik (IMBEI)
    Obere Zahlbacher Straße 69
    55131 Mainz
    Tel.: 06131/ 17-6852

    E-Mail: uni-mainz.de
    Internet: www.imbei.de
    Christian Guest

  5. #5

    Default Re: cannot call a process via telnet


    >
    > Its not the whole file. I paste some parts of the script into the mail
    > ,renamed the variables in english ... but I also doesn't use strict.[/ref]
    Maybe 

    It should help, if it doesn't lead you to the error then paste the
    actual code, or at least some of it. If you paste code similar but not
    the same we can't tell whether the problems from your re-entry are the
    reason for failure or something else. You also don't really need to
    change variable names to english, variables are variables, and that is
    one of the beautiful things about Perl, because of the sigils, the
    context, and the other punctuation we can grok the meaning without
    actually knowing what the variable names mean. We may not all speak
    German here, but we definitely all speak Perl :-)....

    http://danconia.org
    Wiggins Guest

  6. #6

    Default Re: cannot call a process via telnet

    > As I expact, I just fixed the scope errors but the problem remains. 

    Generally we want our subroutines to be passed arguments and return
    values. The above has avoided the scoping symptom but not really fixed
    the encapsulation problem. You should pass the username and password to
    the sub rather than calling from the sub into the global scope.
     

    Its considered better style to declare your variables at first usage
    rather than as a list at the top. This helps to get proper scoping and
    to avoid spelling errors, etc.
     
    '/\[datagate\]\/KOMM\/datagate 
    >
    > $t->open ("komm") or die "cannot establish a connection!\n";
    > $rs = $t->login ($username, $passwd) or die "login failed\n";
    >
    >
    > ra = $t->print ( $command_1 ) or die "cannot change dir!\n";
    > $rs = $t->print ( "./komm-test.pl" ) or die "cannot start script!\n";[/ref]

    The C<print> method is not used for running commands but is instead used
    for sending input to the process on the other side. You should be using
    the C<cmd> method to issue a command. Check back to the Net::Telnet
    docs, specifically for the two methods. If 'komm-test.pl' is expecting
    input from STDIN for instance you would use C<print> otherwise you
    aren't likely to need it.

    perldoc Net::Telnet for the doentation.
     
    doesn't start 

    http://danconia.org
    Wiggins Guest

  7. #7

    Default Re: cannot call a process via telnet

    Okay now I tryed instead of:
    $rs = $t->print ( "./komm-test.pl" ) or die "cannot execute !\n";

    this:

    $rueck_s = $t->cmd ( "./komm-test.pl" ) or die "Kann kein Script starten!\n";

    and get this message:
    command timed-out at Refdb.pm line 94
    And this is absolutly normal because the script which is called takes a lot
    of time to execute. But to call it with an '&' dosn't fix it neighter!!!!
    What can I do in this case?

    Thank you very much...

    Gruss Christian


    --
    Christian Stalp

    Institut für Medizinische Biometrie, Epidemiologie und Informatik (IMBEI)
    Obere Zahlbacher Straße 69
    55131 Mainz
    Tel.: 06131/ 17-6852

    E-Mail: uni-mainz.de
    Internet: www.imbei.de
    Christian Guest

  8. #8

    Default Re: cannot call a process via telnet

    Please group reply so others can help and be helped, and to prevent
    getting (accidentally) ignored.
     
    starten!\n"; 
    a lot 

    It appears from the docs that the C<cmd> method can take a timeout as
    well. I suspect adding the '&' will cause problems because the shell
    will return control to Net::Telnet and there will be no way to
    communicate with the process. Note that when you switch to include
    other arguments with C<cmd> it appears you need to pass the command with
    the 'String' key.
     

    You need to read the docs thoroughly before asking questions....

    http://danconia.org
    Wiggins Guest

  9. #9

    Default Re: cannot call a process via telnet

     

    Sure but this doesn't make any change if I call the cmd with a prepared
    string or a directly into the brackets. I was at this point a few hours
    before. Calling a process with the cmd- method. Then I found the print -
    method in the docs. But both have the same problem: sending a command over
    the telnet without waiting for the answer. And I don't want to change the
    timeout because the script has more functions than to wait for another
    process exit. The docs doesn't give any solution how to make this!

    Its no problem to call a process manualy over the telnet with a '&' at least
    our servers!

    Gruss Christian
    Christian Guest

  10. #10

    Default Re: cannot call a process via telnet


    >
    > Sure but this doesn't make any change if I call the cmd with a prepared
    > string or a directly into the brackets. I was at this point a few hours
    > before. Calling a process with the cmd- method. Then I found the print -
    > method in the docs. But both have the same problem: sending a command[/ref]
    over 
    least 

    huh, one might think that would have been helpful to mention up front.
    Now that we have come full circle I will point you once again back to
    the docs, and this time specifically the C<waitfor> method and the list
    of 3-4 examples at the bottom of the docs that talk about how to
    interact with a program, specifically the ssh example and the passwd
    example. This should allow you to turn off the timeout, or at least set
    it to something arbitrarily high.

    http://danconia.org
    Wiggins Guest

  11. #11

    Default Re: cannot call a process via telnet



    ----- Original Message -----
    From: Christian Stalp <uni-mainz.de>
    Date: Tuesday, October 12, 2004 12:18 pm
    Subject: Re: cannot call a process via telnet
     
    > timeout as 
    > shell> will return control to Net::Telnet and there will be no way to 
    > command with 
    >
    > Sure but this doesn't make any change if I call the cmd with a
    > prepared
    > string or a directly into the brackets. I was at this point a few
    > hours
    > before. Calling a process with the cmd- method. Then I found the
    > print -
    > method in the docs. But both have the same problem: sending a
    > command over
    > the telnet without waiting for the answer. And I don't want to
    > change the
    > timeout because the script has more functions than to wait for
    > another
    > process exit. The docs doesn't give any solution how to make this!
    >
    > Its no problem to call a process manualy over the telnet with a
    > '&' at least
    > our servers![/ref]
    Gruss,
    Perhaps what you are looking for is net-rexec ?? 

    mgoland@optonline.net Guest

  12. #12

    Default Re: cannot call a process via telnet

    I just want you to know that the solution of my problem was to change the
    prompt!

    When I call the remote bash via telnet to change the directory it expacted
    the old prompt which was guilty while login:
    Prompt => '/\[datagate\]\/KOMM\/datagate >

    But after changing the directory the prompt was modified. So the solution to
    call a simple "ls" is:

    ra = $t->cmd ( String => 'ls',
    Prompt => '/\[datagate\]\/KOMM\/datagate\/STALP\/PERL\/BERT 
    print ra;

    And to call a routine is:

    $rs = $t->cmd ( String => 'komm-test.pl',
    Prompt => '/\[datagate\]\/KOMM\/datagate\/STALP\/PERL\/BERT 


    Hope this helps anybody who'll encounter the same problem ...
    MIND THE PROMPT ;-)

    Thanks all for help

    Gruss Christian


    --
    Christian Stalp

    Institut für Medizinische Biometrie, Epidemiologie und Informatik (IMBEI)
    Obere Zahlbacher Straße 69
    55131 Mainz
    Tel.: 06131/ 17-6852

    E-Mail: uni-mainz.de
    Internet: www.imbei.de
    Christian Guest

Similar Threads

  1. #38796 [NEW]: Self-call __destructor from child process
    By fiw at mail dot ru in forum PHP Bugs
    Replies: 10
    Last Post: September 12th, 08:01 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139