Quantcast
Channel: Active questions tagged expect - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 157

expect script doesn't change password on Solaris

$
0
0

I have this script I run from a Linux machine to change root password on remote Solaris machine reachable by ssh.All seems to be fine, passwd command asks for a password, second password, reply that is not 8 chars long and finishes with ... updated successfully, but when I go to Solaris and I check, password is not changed. shadow file is not modified.I can change password directly on the Solaris box with no problems.

$ cat ./expect2.txt#!/usr/bin/expect --# Input: username password hostnameset USER [lindex $argv 0]set PASS [lindex $argv 1]set IP   [lindex $argv 2]spawn ssh user1@$IPexpect "user1" spawn sudo passwd $USERexpect "assword:"send "$PASS\r"expect "assword:"send "$PASS\r"expect eofexitexit

I run the script:

$ expect  ./expect2.txt root abc123 host1spawn ssh user1@host1host1 user1 : spawn sudo passwd rootChanging password for user root.New password:BAD PASSWORD: The password is shorter than 8 charactersRetype new password:passwd: all authentication tokens updated successfully.

Debug

$ expect -d ./expect2.txt root abc123 host1expect version 5.45.4argv[0] = expect  argv[1] = -d  argv[2] = ./expect2.txt  argv[3] = root  argv[4] = abc123  argv[5] = host1set argc 3set argv0 "./expect2.txt"set argv "root abc123 host1"executing commands from command file ./expect2.txtspawn ssh user1@host1parent: waiting for sync byteparent: telling child to go aheadparent: now unsynchronized from childspawn: returns {2669765}expect: does "" (spawn_id exp4) match glob pattern "user1"? nomatch glob pattern "user1"? yesexpect: set expect_out(0,string) "user1"expect: set expect_out(spawn_id) "exp4"spawn sudo passwd rootparent: waiting for sync byteparent: telling child to go aheadparent: now unsynchronized from childspawn: returns {2669769}expect: does "" (spawn_id exp7) match glob pattern "assword:"? noChanging password for user root.New password:expect: does "Changing password for user root.\r\nNew password: " (spawn_id exp7) match glob pattern "assword:"? yesexpect: set expect_out(0,string) "assword:"expect: set expect_out(spawn_id) "exp7"expect: set expect_out(buffer) "Changing password for user root.\r\nNew password:"send: sending "abc123\r" to { exp7 }expect: does " " (spawn_id exp7) match glob pattern "assword:"? noBAD PASSWORD: The password is shorter than 8 charactersRetype new password:expect: does " \r\nBAD PASSWORD: The password is shorter than 8 characters\r\nRetype new password: " (spawn_id exp7) match glob pattern "assword:"? yesexpect: set expect_out(0,string) "assword:"expect: set expect_out(spawn_id) "exp7"expect: set expect_out(buffer) " \r\nBAD PASSWORD: The password is shorter than 8 characters\r\nRetype new password:"send: sending "abc123\r" to { exp7 }passwd: all authentication tokens updated successfully.expect: read eofexpect: set expect_out(spawn_id) "exp7"expect: set expect_out(buffer) " \r\npasswd: all authentication tokens updated successfully.\r\n"

Viewing all articles
Browse latest Browse all 157

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>