[Gllug] problem with expect
Pooly
pooly7 at gmail.com
Sun Dec 21 17:03:32 UTC 2008
Hi,
I'm trying to create a script to update a password in a
non-interactive way. It's working on my laptop but fails on my server.
Both are running the same configuration, using Etch.
This is the script:
--------------------
#!/usr/bin/expect -f
# Change user passwd
set timeout 30
strace 4
set password [lindex $argv 1]
set old_password [lindex $argv 2]
spawn passwd [lindex $argv 0]
sleep 1
expect "(current) UNIX password: $"
send "$old_password\r"
expect "Enter new UNIX password: $"
send "$password\r"
expect "Retype new UNIX password: $"
send "$password\r"
expect eof
--------------------
On the server the output looks like this:
myuser at server:~$ /home/myuser/adm/chpasswd myuser NewPasswd OldPasswd
2 lindex $argv 0
1 set username [lindex $argv 0]
2 lindex $argv 1
1 set password [lindex $argv 1]
2 lindex $argv 2
1 set old_password [lindex $argv 2]
1 spawn passwd $username
spawn passwd myuser
1 sleep 1
1 expect "(current) UNIX password: $"
Changing password for myuser
(current) UNIX password: 1 send "$old_password\r"
1 expect "Enter new UNIX password: $"
OldPasswd
Enter new UNIX password: 1 send "$password\r"
1 expect "Retype new UNIX password: $"
NewPasswd
1 send "$password\r"
1 expect eof
Retype new UNIX password: 1 exit 0
----------------------------------------------------
but strangely enough, on my laptop:
test at mars:/home/test/adm$ ./chpasswd test NewPasswd OldPasswd
2 lindex $argv 1
1 set password [lindex $argv 1]
2 lindex $argv 2
1 set old_password [lindex $argv 2]
2 lindex $argv 0
1 spawn passwd [lindex $argv 0]
spawn passwd test
1 sleep 1
1 expect "(current) UNIX password: $"
Changing password for test
(current) UNIX password: 1 send "$old_password\r"
1 expect "Enter new UNIX password: $"
OldPasswd
Enter new UNIX password: 1 send "$password\r"
1 expect "Retype new UNIX password: $"
NewPasswd
Retype new UNIX password: 1 send "$password\r"
1 expect eof
NewPasswd
passwd: password updated successfully
1 exit 0
-------------------------------------------------------------
Any ideas why it's going wrong on the server ?
Thanks
--
http://www.w-fenec.org : webzine rock metal indus
--
Gllug mailing list - Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug
More information about the GLLUG
mailing list