Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
When I telnet, it will read “test” and execute the commands. But when I ssh, for some reason it does execute the commands. Any help is greatly appreciated, I’m not really sure how this “magic” thing works.if ($input[0] eq "ssh"){ # SSH session my $exp = new Expect; $exp->raw_pty(1); $exp = Expect->spawn("$cmd\r"); $exp->expect(1, '-ex', "$_"); system("stty -echo"); $exp->expect (1, '-ex', "$_"); $password = <STDIN>; system("stty echo"); chomp $password; $exp->send ("$password\r"); $exp->expect (1, '-ex', "$login[1]:~#"); my $input = <STDIN>; chomp $input; if ($input =~ "@@"){ $input =~ s/@@//; my $script = "/root/Desktop/$input"; open(SCRIPT, "./$input|"); while (<SCRIPT>){ $exp->send ("$_\r"); } close (SCRIPT); } else {$exp->send ("$input\r");} } else{ # Telnet session my $exp = new Expect; $exp->raw_pty(1); $exp = Expect->spawn("$cmd\r"); $exp->expect(1, '-ex', "Password:"); system("stty -echo"); $password = <STDIN>; chomp $password; $exp->send ("$password\r"); system("stty echo"); $exp->expect(1, '-ex', "$_"); # User mode $command = <STDIN>; chomp $command; $exp->send ("$command\r"); $exp->expect (1, '-ex', "$_"); # Privileged mode system("stty -echo"); $password = <STDIN>; chomp $password; system("stty echo"); $exp->send( "$password\r"); $exp->expect (1, '-ex', "$_"); my $input = <STDIN>; chomp $input; if ($input =~ "@@"){ $input =~ s/@@//; my $script = "/$dir/$input"; open(SCRIPT, "./$input|"); while (<SCRIPT>){ $exp->send ("$_\r"); } else {$exp->send ("$input\r");} }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Help Using Magic Script
by choroba (Cardinal) on Jun 07, 2010 at 15:43 UTC | |
|
Re: Help Using Magic Script
by Anonymous Monk on Jun 07, 2010 at 15:40 UTC |