[vox-tech] [OT] Pumping a password using Expect

timriley timriley at appahost.com
Thu Jan 5 17:33:40 PST 2006


Hi All:

I'm trying to synchronize an Oracle database on one
computer from a Mysql database on the computer
“barracuda” by using Expect. Mysql has a nifty logging
feature which places all insert, update, delete, and other
altering commands into a file. My goal is to have
the "one" computer's crontab log into barracuda;
then barracuda will kick off a process which simply
"cat"s the Mysql log files. The "one" computer will
then capture those SQL statements and send them to sqlplus.

The challenge is for the "one" computer to send the
password to barracuda because barracuda (or any *nix computer)
accepts passwords only from a tty. OK, so here's
where Expect shines. Expect is a "see and say" programming
language which knows how to pump strings to a tty.
(It's called "see and say" because when it sees
"Password:", it can be programmed to say "thepassword".)

Well, Expect works find when the process is kicked off
from the command line; however, it fails to work when
executed from crontab.

Here is the Expect script:

#!/usr/bin/expect --
exp_internal 1
spawn ssh -l mysql_sync barracuda
expect “mysql_sync at barracuda’s password: “
send “thepassword\r”
interact

Here is the output when the Expect script
successfully executes from the command line:

spawn ssh -l mysql_sync barracuda
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {26147}

expect: does "" (spawn_id exp4) match glob pattern "mysql_sync at barracuda's password: "? no
mysql_sync at barracuda's password: 
expect: does "mysql_sync at barracuda's password: " (spawn_id exp4) match glob pattern "mysql_sync at barracuda's password: "? yes
expect: set expect_out(0,string) "mysql_sync at barracuda's password: "
expect: set expect_out(spawn_id) "exp4"
expect: set expect_out(buffer) "mysql_sync at barracuda's password: "
send: sending "thepassword\r" to { exp4 }
tty_raw_noecho: was raw = 0  echo = 1
spawn id exp4 sent <\r\n>

Warning: No xauth data; using fake authentication data for X11 forwarding.
spawn id exp4 sent < \r\n\r\n 
<snip>
  ************************************************
  *                SYSTEM INFO                   *
  ************************************************

  Hostname              :       barracuda

<snip>

spawn id exp4 sent <Connection to barracuda closed.\r\r\n>
Connection to barracuda closed.
interact: received eof from spawn_id exp4
tty_set: raw = 0, echo = 1
tty_set: raw = 3, echo = 0

Here is the output when the Expect script
fails to execute from crontab:

spawn ssh -l mysql_sync barracuda
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {26242}

expect: does "" (spawn_id exp3) match glob pattern "mysql_sync at barracuda's password: "? no
mysql_sync at barracuda's password: 
expect: does "mysql_sync at barracuda's password: " (spawn_id exp3) match glob pattern "mysql_sync at barracuda's password: "? yes
expect: set expect_out(0,string) "mysql_sync at barracuda's password: "
expect: set expect_out(spawn_id) "exp3"
expect: set expect_out(buffer) "mysql_sync at barracuda's password: "
send: sending "thepassword\r" to { exp3 }
spawn id exp0 sent <\nexit 0\n\n>
interact: received eof from spawn_id exp0

Notice that whereas it seems to send the password,
there is no evidence that barracuda’s computer
was logged into.

How do you have a crontab executed process using Expect
pump a password to another computer?

--
Tim Riley

  



More information about the vox-tech mailing list