LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
LinkBack Search this Thread
Old 03-03-2005, 04:52 PM   #1
Arodef
Member
 
Registered: Apr 2004
Distribution: Centos, Fedora
Posts: 114

Rep: Reputation: 15
Need help using expect to set password


I'm trying to do the most basic expect example but my script is not working. Here's the code:

#!/usr/local/bin/expect --
# wrapper to make passwd be noninteractive
# username is passed as 1st arg, passwd as 2nd
# Executable only by root

#added timeout to see where problem occurs
set timeout -1
spawn passwd [lindex $argv 0]
set pass [lindex $argv 1]
expect "password:"
send "$pass\r"
expect "password:"
send "$pass\r"
expect eof
#end script

Here's what happens when I run it:

[root@local root]# ./setpass test ashgt21
spawn passwd test
Changing password for user test.
New password: ashgt43
<HANGS HERE>

It looks like it is hanging expect the second password: prompt? It seems to be stuck after I sent the password the first time. Any ideas?

BTW, I can manually set the password after that script fails using the same password and user account (to rule out those 2 things as the problem):

[root@local root]# passwd test
Changing password for user test.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[root@local root]#



Any ideas on what I'm doing wrong?
 
Old 03-03-2005, 05:55 PM   #2
Arodef
Member
 
Registered: Apr 2004
Distribution: Centos, Fedora
Posts: 114

Original Poster
Rep: Reputation: 15
Here's the diagnostic output from expect:

[root@local root]# ./setpass test ashgt21
expect version 5.43.0
argv[0] = /usr/local/bin/expect argv[1] = -d argv[2] = ./setpass argv[3] = test argv[4] = ashgt21
set argc 2
set argv0 "./setpass"
set argv "test ashgt21"
executing commands from command file ./setpass
spawn passwd test
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {5021}

expect: does "" (spawn_id exp4) match glob pattern "password:"? no
Changing password for user test.

expect: does "Changing password for user test.\r\n" (spawn_id exp4) match glob pattern "password:"? no
New password:
expect: does "Changing password for user test.\r\nNew password: " (spawn_id exp4) match glob pattern "password:"? yes
expect: set expect_out(0,string) "password:"
expect: set expect_out(spawn_id) "exp4"
expect: set expect_out(buffer) "Changing password for user test.\r\nNew password:"
send: sending "ashgt21\r" to { exp4 }

expect: does " " (spawn_id exp4) match glob pattern "password:"? no
ashgt21

expect: does " ashgt21\r\n" (spawn_id exp4) match glob pattern "password:"? no

<HANGS HERE>

Last edited by Arodef; 03-03-2005 at 06:34 PM.
 
Old 03-03-2005, 07:30 PM   #3
Arodef
Member
 
Registered: Apr 2004
Distribution: Centos, Fedora
Posts: 114

Original Poster
Rep: Reputation: 15
Found the solution, I need a sleep 1 statement after the expect password statements. Thank god for google!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What should I do to set root password backpacker Linux - Newbie 1 06-10-2005 03:19 AM
Expect.pm /bin/su incorrect password newuser455 Linux - Software 5 02-06-2005 04:23 PM
Expect.pm /bin/su incorrect password newuser455 Linux - Software 0 01-21-2005 06:38 PM
How to set no password rquin66 Fedora 17 01-01-2004 04:06 AM
Cant set password for new users ribbones Linux - General 1 09-03-2003 10:56 AM


All times are GMT -5. The time now is 03:32 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration