mnlight has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to run a second perl script located on a remote box. When the script is kicked off it returns nothing until it returns to the prompt. Doing it with a Telnet session the script will not kick off because I am not able to do a match before the prompt returns. How do I keep the telnet session open long enough to run the script.
my $th = new Net::Telnet (input_log => "$dir/$log", dump_log => (*STDOUT), Host => "$server", Prompt => '/sybase?/'); print "******DUMPING $cltdb TRANSACTION******\n"; $th->login("user", "$unixpass"); my @lines = $th->cmd("backup.pl Server.Name=$dbsrvr Backup.Database=$c +ltdb Backup.Type=tran"); $th->waitfor('/ /'); print @lines; $th->waitfor('/sybase?/'); print @lines;

Replies are listed 'Best First'.
Re: Net::Telnet time outs
by peschkaj (Pilgrim) on Aug 12, 2002 at 22:37 UTC
    I would say that your prompt looks funny. Additionally, I would turn up the timeout in your connection info:
    my $th = new Net::Telnet (input_log => "$dir/$log", dump_log => (*STDOUT), Host => "$server", Prompt => '/sybase?/', Timeout => 600); ### A timeout of 600 will give you 10 minutes ### to wait for the processes to complete remotely
    I had a fair number of problems like this with some telnetting between HP-UX and SUN boxes. The best thing (I found) to look for is the final prompt character, rather than the whole prompt string. The perldocs for Net::Telnet are quite extensive in the newest version (I have it with my perl 5.8.0 build) and they are a great help.
      dump_log output: < 0x00000: 74 65 72 72 61 3a 73 79 62 61 73 65 24 20 terra:sybase$ > 0x00000: 2f 6e 6d 73 2f 73 79 73 74 65 6d 2f 62 69 6e 2f > 0x00010: 73 79 62 61 73 65 2f 62 61 63 6b 75 70 5f 73 79 > 0x00020: 62 61 73 65 2e 70 6c 20 53 65 72 76 65 72 2e 4e backup_sybase.pl Server.Name=LUNA Backup.Database=ES Backup.Type=tran > 0x00030: 61 6d 65 3d 4c 55 4e 41 20 42 61 63 6b 75 70 2e > 0x00040: 44 61 74 61 62 61 73 65 3d 45 53 20 42 61 63 6b > 0x00050: 75 70 2e 54 79 70 65 3d 74 72 61 6e 0d 0a < 0x00000: 2f 6e 6d 73 2f 73 79 73 74 65 6d 2f 62 69 6e 2f < 0x00010: 73 79 62 61 73 65 2f 62 61 63 6b 75 70 5f 73 79 < 0x00020: 62 61 73 65 2e 70 6c 20 53 65 72 76 65 72 2e 4e < 0x00030: 61 6d 65 3d 4c 55 4e 41 20 42 61 63 6b 75 70 2e < 0x00040: 44 61 74 61 62 61 73 65 3d 45 53 20 42 61 63 6b < 0x00050: 75 70 2e 54 79 70 65 3d 74 72 61 6e 0d 0a
        Ahh, ok. Looks like what is happening is that the command actually gets executed, but it takes longer than your timeout to complete.

        I would do this:
        my @lines = $th->cmd(String => ("backup.pl Server.Name=$dbsrvr Backup. +Database=$c", Timeout => 600);
        instaed of my @lines = $th->cmd("backup.pl Server.Name=$dbsrvr Backup.Database=$c
        This will give you a long timeout on that command only.

        Actually seeing the command in the dump_log usually means that you got that far in the script, in this case, the command would never have been executed if the prompt was not matched. If 10 minutes is not enough time for the backup to complete you might want to up the timeout even further.

        "Nothing is sure but death and taxes" I say combine the two and its death to all taxes!
Re: Net::Telnet time outs
by Rex(Wrecks) (Curate) on Aug 12, 2002 at 22:22 UTC
    Hmm, what does your dump log say? does the prompt actually match? (sybase seems like a strange prompt to me...and you will want to escape the '?' if that is part of your prompt) and if so does your username and password match the default login prompts?

    posting the output of the dump_log would be handy to debug.

    I suspect you are not matching your original login prompt. Also you have 2 waitfors in sucession at the end of your script (separated by a print that has nothing to do with the telnet session) Why? you should only need one of them.

    "Nothing is sure but death and taxes" I say combine the two and its death to all taxes!