Irregular Expressions

May 10 2010   1:23PM GMT

Automating system tasks with Perl – Part 2

Dan O'Connor Dan O'Connor Profile: Dan O'Connor

Here is a more complicated example that I created for Expect.

Set up the connection again.

        my $ssh = Net::SSH::Expect->new (
            host => "",
            password=> 'pass87word',
            user => 'bnegrao',
            raw_pty => 1

        my $login_output = $ssh->login();
        if ($login_output !~ /Welcome/) {
            die "Login has failed. Login output was $login_output";

We have a prompt now ( if it did not die ). So here is a little snippit of code,

        $ssh->send("su - oracleuser");
        $ssh->waitfor('$',1); # you could get a little more error control here but I have not had a problem.
        $ssh->send("sqlplus /nolog"); #Login to the DB
        $ssh->waitfor('SQL',5); # wait 5 seconds for the prompt.

I am not going to take that any further, you should see where that is going.  You can also do other things just you were like at the prompt.

Send ‘cd /path/to/something’, then you can execute something from in the context of the that dir, ‘./execute.bin’.

You can also do SIGNALS over the connect to pids. You can send a ‘kill -STOP pid’ or a ‘kill – CONT pid’, so you can mess with and create background pids, ( You may need to use disown for this to work properly ).


 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: