l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
September 2: Social gathering
Next Installfest:
TBD
Latest News:
Aug. 18: Discounts to "Velocity" in NY; come to tonight's "Photography" talk
Page last updated:
2006 Jan 05 19:48

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
[vox-tech] [OT] Pumping a password using Expect
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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



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@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@barracuda's password: "? no
mysql_sync@barracuda's password:
expect: does "mysql_sync@barracuda's password: " (spawn_id exp4) match glob pattern "mysql_sync@barracuda's password: "? yes
expect: set expect_out(0,string) "mysql_sync@barracuda's password: "
expect: set expect_out(spawn_id) "exp4"
expect: set expect_out(buffer) "mysql_sync@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@barracuda's password: "? no
mysql_sync@barracuda's password:
expect: does "mysql_sync@barracuda's password: " (spawn_id exp3) match glob pattern "mysql_sync@barracuda's password: "? yes
expect: set expect_out(0,string) "mysql_sync@barracuda's password: "
expect: set expect_out(spawn_id) "exp3"
expect: set expect_out(buffer) "mysql_sync@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



_______________________________________________
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech



LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
Appahost Applications
For a significant contribution towards our projector, and a generous donation to allow us to continue meeting at the Davis Library.