From bonsaime at gmail.com Fri Jan 4 18:02:26 2008 From: bonsaime at gmail.com (Jesse Callaway) Date: Fri Jan 4 18:02:30 2008 Subject: [macosx-unix] expect trouble Message-ID: Hey all, I've never really played around with expect, so I'm not sure if it's problems with the osx pty and expect, or just me. Anyway I'm trying to run a bunch of scripts while typing in my password only once. Some say an agent would best serve me, but I just want to learn to use expect properly anyway. Here's my script: #!/usr/bin/expect -f send_user "RSA key passphrase: " stty -echo expect_user -re "(.*)\n" {set PASS $expect_out(1,string)} send_user "\n" stty echo spawn rsync -aqz jesse@server.com:/etc /Users/jesse/Documents/Server\ Backups\ and\ Configs/server.com/ expect "id_rsa': " send_user "\n" send "$PASS\r" When I run the script I get the prompt to enter the passphrase, then it spawns the rsync job. I can see rsync and ssh spawn in top. Then I see a prompt on my terminal to "Enter passphrase for key '/Users/jesse/.ssh/id_rsa':" And everything quits immediately. Do I need to be looking at stderr? Should I try yax? Should I try one of python or perl expect modules? -jesse From bonsaime at gmail.com Sat Jan 5 00:28:14 2008 From: bonsaime at gmail.com (Jesse Callaway) Date: Sat Jan 5 00:28:43 2008 Subject: [macosx-unix] expect trouble In-Reply-To: <23BEABD6-E517-4135-AAD7-8F868923B126@23x.net> References: <23BEABD6-E517-4135-AAD7-8F868923B126@23x.net> Message-ID: On Jan 4, 2008 7:40 PM, Jared ''Danger'' Earle wrote: > On 4 Jan 2008, at 23:02, Jesse Callaway wrote: > > Do I need to be looking at stderr? Should I try yax? Should I try one > > of python or perl expect modules? > > > Is there a reason you're not using SSH keys? > 1. Read the post again. 2. I don't know, just stick with #1 for now. I'm sorry. It's easy to be curt on the web. So I'll explain... It's really obvious that I'm using SSH keys if you read the post all the way through. Please don't post a reply unless you think you can help with my problem. This is summarized in the last sentence of my first paragraph. It is further illustrated in the example script. But that's not the problem. The problem is that for some reason something is not happening with expect the way I want it to. I tried looking at the autoexpect dump of my action, but I wasn't able to correlate it because autoexect uses exact matches for the patterns which confuses my efforts to debug. Maybe I'm not matching the prompt for the ssh key passphrase properly, but I'm pretty sure I am because of my attempts with the '-d' flag. It shows that the patterns (i've tried 2) "id_rsa\': ", and "id_rsa': " match. I'm not sure why they both match since an escaped single quote should not match if the escape character.. i'm losing my train of thought already. Anyway, I'll post my debug output on mondag when I care about it. It's the weekend! -jesse From bonsaime at gmail.com Tue Jan 8 14:17:16 2008 From: bonsaime at gmail.com (Jesse Callaway) Date: Tue Jan 8 14:17:22 2008 Subject: [macosx-unix] expect trouble In-Reply-To: References: <23BEABD6-E517-4135-AAD7-8F868923B126@23x.net> Message-ID: On Jan 5, 2008 7:37 AM, Jared ''Danger'' Earle wrote: > On 5 Jan 2008, at 05:28, Jesse Callaway wrote: > > I'm sorry. It's easy to be curt on the web. So I'll explain... It's > > really obvious that I'm using SSH keys if you read the post all the > > way through. > > > Ok, I got caught up in passphrase vs password. > > This part is written for passwords: > send "$PASS\r" > > For passphrases, I'd probably use send_tty instead. > > I've seen expect work with ssh key passphrases before, so it can be > done. > > -- > Jared Earle, Nightfall Games, jared@23x.net - http://www.23x.net > "Life is SPORK, Highness! Anyone who says differently is selling > something" > This fell off the list for some reason. Sorry all. Anyway, I tried using send_tty, and the outcome was basically the same except that my password was echoed to my terminal, and not to the process. Hey, so I figured it out. If you don't tell expect to do anything further it kills the spawned processes so that the script can exit without hanging. I guess it's aggressive in terms of cleaning up after itself. Fixed it by adding 'expect eof' as the last line. Anyway, thanks for helping out Jared. -jesse From peter_booth at mac.com Tue Jan 8 15:15:34 2008 From: peter_booth at mac.com (Peter Booth) Date: Tue Jan 8 15:21:31 2008 Subject: [macosx-unix] expect trouble In-Reply-To: References: <23BEABD6-E517-4135-AAD7-8F868923B126@23x.net> Message-ID: FWIW I have found Ruby's net-ssh and, for many use cases, Capistrano are great higher level replacements for expect. Capistrano is useful when you want to execute code (and deploy stuff) to multiple machines. On Jan 8, 2008, at 2:17 PM, Jesse Callaway wrote: > On Jan 5, 2008 7:37 AM, Jared ''Danger'' Earle wrote: >> On 5 Jan 2008, at 05:28, Jesse Callaway wrote: >>> I'm sorry. It's easy to be curt on the web. So I'll explain... It's >>> really obvious that I'm using SSH keys if you read the post all the >>> way through. >> >> >> Ok, I got caught up in passphrase vs password. >> >> This part is written for passwords: >> send "$PASS\r" >> >> For passphrases, I'd probably use send_tty instead. >> >> I've seen expect work with ssh key passphrases before, so it can be >> done. >> >> -- >> Jared Earle, Nightfall Games, jared@23x.net - http://www.23x.net >> "Life is SPORK, Highness! Anyone who says differently is selling >> something" >> > > This fell off the list for some reason. Sorry all. Anyway, I tried > using send_tty, and the outcome was basically the same except that my > password was echoed to my terminal, and not to the process. > > Hey, so I figured it out. If you don't tell expect to do anything > further it kills the spawned processes so that the script can exit > without hanging. I guess it's aggressive in terms of cleaning up after > itself. > > Fixed it by adding 'expect eof' as the last line. > > Anyway, thanks for helping out Jared. > > -jesse > _______________________________________________ > macosx-unix mailing list > macosx-unix@lesmuug.org > http://beth.lesmuug.org/mailman/listinfo/macosx-unix