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

Monks, I once again come to you for the great wisdom you possess.

I am trying to execute an 'expect->send' command from my script through to the cluster ssh (CSSH) control window. However, even though debug shows expect sends the command to the proper spawn ID, the plain text is not sent, in this case is the password. Man CSSH does not show a password option, only an username option.

my $command = "cssh -G -T 'OOPCSSH' -l username $goto"; my $dl = Expect->new(); $dl->raw_pty(1); #$dl->log_stdout(0); $dl->spawn($command) or die "Cannot spawn $command: $! +\n"; #dl->expect(undef, "assword"); sleep 5; $dl->send("$passwd\r"); #$dl->expect(undef, "\$"); #$dl->send("$passwd\r"); #}

As you can see by the # I have tried several diff ways to send the command, the way currently configured, is the only way I get a successful send in DEBUG but still no password sent, login fails... Any ideas, would greatly ease the sound of my head hitting the wall..



DEBUG OUTPUT:
Spawned 'Proc::Background=HASH(0x87abc5c)' spawn id(4) Pid: 17507 Tty: /dev/pts/12 at /usr/local/share/perl/5.8.8/Expect.pm line 181 Expect::spawn('Expect=GLOB(0x87abce0)', 'Proc::Background=HASH(0x8 +7abc5c)') called at ./Layout.pl line 453 main::go() called at /usr/local/lib/perl/5.8.8/Tk.pm line 247 eval {...} called at /usr/local/lib/perl/5.8.8/Tk.pm line 247 Tk::__ANON__('Tk::Button=HASH(0x877a450)') called at /usr/local/li +b/perl/5.8.8/Tk/Button.pm line 111 Tk::Button::butUp('Tk::Button=HASH(0x877a450)') called at /usr/loc +al/lib/perl/5.8.8/Tk.pm line 406 eval {...} called at /usr/local/lib/perl/5.8.8/Tk.pm line 406 Tk::MainLoop() called at ./Layout.pl line 427 SENDS PASSWD: Sending 'PassWD1\r' to spawn id(4) at /usr/local/share/perl/5.8.8/Expect.pm line 1264 Expect::print('Expect=GLOB(0x87abce0)', 'PassWD1\x{d}') called at +./Layout.pl line 456 main::go() called at /usr/local/lib/perl/5.8.8/Tk.pm line 247 eval {...} called at /usr/local/lib/perl/5.8.8/Tk.pm line 247 Tk::__ANON__('Tk::Button=HASH(0x877a450)') called at /usr/local/li +b/perl/5.8.8/Tk/Button.pm line 111 Tk::Button::butUp('Tk::Button=HASH(0x877a450)') called at /usr/loc +al/lib/perl/5.8.8/Tk.pm line 406 eval {...} called at /usr/local/lib/perl/5.8.8/Tk.pm line 406 Tk::MainLoop() called at ./Layout.pl line 427

Replies are listed 'Best First'.
Re: Expect and CSSH
by jffry (Hermit) on Feb 14, 2012 at 19:32 UTC

    Your Expect syntax is simple enough that it looks like it should work in typical situations. But it seems that Cluster SSH is not a simple command line tool.

    Sure, it opens a console, but that is inside of another window. Thus, the plain text being sent to the cssh program might not be going to the new console tty itself but to the windowing code in which the console runs.

    What I wrote is merely my guess after glancing at some docs.

    You should try contacting the author (duncan_ferguson@users.sf.net) of Cluster SSH. He seems to welcome inquiries about using his product.

Re: Expect and CSSH
by salva (Canon) on Feb 15, 2012 at 08:36 UTC
    Is using CSSH a requeriment?

    I ask because you are trying to automate an application that was never intended to be automated and it may be easy to use other approaches.

    For instance, if you want to run commands in several hosts in parallel through ssh, Net::OpenSSH::Parallel may be a better option.

    If you want to display the output in several terminals as cssh does, then you can use GTK+ and the excellent VTE terminal emulation widget (Gnome2::Vte). AFAIK, no similar widget exist for Tk.

    You may also like to investigate urxvt, a terminal emulator with an embedded perl interpreter.

      @Slava: Thanks Much! Not a requirement, but we have re-written CSSH to our needs and was implementing a control panel of sorts to combine the two into one nice massive tool that works for our needs. I appreciate the tips and will review the alternatives, though this issue I have ran into is not a showstopper for my project, I was just curious if a Monk or the alike have ran into an similar situation and knew a neat workaround/trick. I have emailed the developer of CSSH to get his insight as well. . . Greatly Appreciate all the response on this issue!

        UPDATE: Issue-Resolved.

        Just wanted to post an update as this may help someone down the road. My issue was that CSSH is using a <<paste>> event to send text to all servers - The paste event is using Selectget, which pulls from either the Primary X buffer or Clipboard, depending on which select=> is defined. So you must either select something or store it in either buffer for it to be sent. I created a few variables with the text needed, then used perls readline to prompt for password once, this is then stored and passed to all the servers on a sleep timer (to ensure the password prompt is hit) Thanks all for taking the time to review this issue..

Re: Expect and CSSH
by danlyke (Initiate) on Feb 14, 2012 at 23:16 UTC
    This is totally not a Perl answer and not an answer to your direct question, but hopefully it will solve your problem.

    You should be using a public/private key pair to enable login without using a password. It's arguably more secure, and once you get it working you'll wonder how you ever got along without it.

    These instructions are for a Un*x like environment, this is entirely possible under Windows too. If you don't currently have an id_*.pub in the .ssh under your home directory, run "ssh-keygen" to create one. Your remote systems also have a ~/.ssh directory, which should be chmod 0700. Append the id_*.pub (by default, id_rsa.pub) file from your client machine (where you're running this Perl) to ~/.ssh/authorized_keys on your server machine (if it doesn't exist yet, create it).

    Now you can ssh and scp from your client machine to your server without having to enter a password, and you can make the password on the server devilishly difficult and long because you no longer have to remember it, and the chances of someone brute forcing it or looking over your shoulder and seeing you type it goes way down.

    And you're not storing your password in plain text in a Perl script, and you can bypass this problem.

      Agreed! However; This is for work and right now our policy does not allow the use of encrypted key pairs, due to our clients needing visibility/accountability.. thus the use of password logins..