From: Schubert on
My mission is very simple.

1. Login in a server through ssh.
2. Then run a batch file.


I use Expect to do the automation.


The script is like this:
--------------------------------------------------------------------------
spawn ssh -p 10022 root@<Server IP address>


expect "root@<Server IP address>'s password: "
send "public\r"


expect {
"\[root@<Server Name>:<Server IP address>\]" {
send "run batch filename.txt\r"}


}


--------------------------------------------------------------------------

Here is the screen output I got if I do this manually:
------------------------------------------------------------------------


> ssh -p 10022 root@<Server IP address>


root@<Server IP address>'s password: public <key-in>

<Server Name>
You're logged on from <Another Server IP address>


[root@<Server Name>:<Server IP address>]: run batch filename.txt
<key-
in>
batch file success message shown
-------------------------------------------------------------------------
But when I use Expect script above to automate the manual steps, it
will get stuck running the batch file. It simply shows the
[root@<Server Name>: <Server IP address>] prompt and then stops. Does
anybody know why this happens? Greatly appreciated.

From: Alexander Skwar on
Schubert <cxbest2004(a)yahoo.com>:

> My mission is very simple.
>
> 1. Login in a server through ssh.
> 2. Then run a batch file.
>
>
> I use Expect to do the automation.

Hm - why are you using Expect to do the automation? I'd suggest
to setup public key authentication. If that's setup, you could
do

ssh $host $command

Ie. login to $host and then run $command. No need for expect.

Alexander Skwar
From: Schubert on
On Feb 14, 5:24 am, Alexander Skwar <alexan...(a)skwar.name> wrote:
> Schubert <cxbest2...(a)yahoo.com>:
>
> > My mission is very simple.
>
> > 1. Login in a server through ssh.
> > 2. Then run a batch file.
>
> > I use Expect to do the automation.
>
> Hm - why are you using Expect to do the automation? I'd suggest
> to setup public key authentication. If that's setup, you could
> do
>
> ssh $host $command
>
> Ie. login to $host and then run $command. No need for expect.
>
> Alexander Skwar

Thanks Alexander, but this is just a very small part of the entire
mission. Do you know what the problem is?

From: Alexander Skwar on
Schubert <cxbest2004(a)yahoo.com>:

> Thanks Alexander, but this is just a very small part of the entire
> mission. Do you know what the problem is?

As I understood, the problem is, that you cannot
run $command after you logged in. To solve that,
I suggest to login to SSH using the "normal"
way (ie. public key authentication" and then have
SSH run the command. Problem solved - although
with a different approach then you used.

Alexander Skwar
From: Carbon on
On Wed, 14 Feb 2007 14:06:04 +0100, Alexander Skwar wrote:
> Schubert <cxbest2004(a)yahoo.com>:
>
>> Thanks Alexander, but this is just a very small part of the entire
>> mission. Do you know what the problem is?
>
> As I understood, the problem is, that you cannot run $command after you
> logged in. To solve that, I suggest to login to SSH using the "normal"
> way (ie. public key authentication" and then have SSH run the command.
> Problem solved - although with a different approach then you used.

For the record I'm backing up about a dozen remote partitions using rsync
and public key authentication. If I want to check the size of a remote
partition I just ssh remotehost "df -h". No passwords, no fuss.