|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hi,
I'm trying to create a script to automate user account creation on two machines. I use expect to handle passwd input. At this first stage (changing password locally) I have difficulty. I hope someone can me out here. Thanks in advance Problem: expect code in a seperate script is working fine when calling it with two params. But calling it from a shell script is a bit hard, where putting expect code in a function, and calling the function with params goes wrong. The error returned is: - end: spawn id exp4 not open while executing "send r" -> spawn passwd 0 sh: /usr/local/bin/stty: not found. 3004-687 User "0" does not exist. A part of the script below: - #!/usr/bin/ksh # passwd_chng () { # These two echo's return correct values. but how to get expect to use them??? echo ${1} echo ${2} RET_0=$(/usr/local/bin/expect -c " set PASSWORD [lindex $argv 1] spawn passwd [lindex $argv 0] expect "password:" send "$PASSWORD\r" expect "password:" send "$PASSWORD\r" expect eof ") echo "-> $RET_0" } _create () { if [ "$(grep -w ^${_USER} /etc/passwd | awk -F ":" '{print $1}')" = "$ {_USER}" ] then # echo "\nUser already exists\n" exit 1 # fi # -- Create the user with mls as primary group. # mkuser pgrp='mls' home="/home/${_USER}" shell='/usr/bin/ksh' gecos="$ {INFO}" ${_USER} # if [[ $? -eq 0 ]] then # -- call expect function. passwd_chng ${_USER} ${PASSWORD} # fi } # #===# Checks and settings # if [ "$(uname -n)" != "HOST1" ] then # echo "\nCan only run from HOST1.\n" exit 1 # fi if [[ $# -ne 3 ]] then # call script with ${0} username "userinfo" password exit 1 # fi if [[ "${1}" = "root" ]] then # echo "Not a good idea!" exit 3 # else # export GEBRUIKER=${1} export VOLNAAM=${2} export PASSWORD=${3} _create $_USER $INFO $PASSWORD # fi |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
2007-07-27, 04:01(-07), relikwie:
> Hi, > > I'm trying to create a script to automate user account creation on two > machines. > I use expect to handle passwd input. At this first stage (changing > password locally) > I have difficulty. You may not need ksh at all. expect is a TCL interpreter, and the TCL language can certainly let you do all ksh can let you do (it can invoke ksh anyway in any case). [...] > end: spawn id exp4 not open > while executing > "send r" > -> spawn passwd 0 > sh: /usr/local/bin/stty: not found. expect runs the stty command to tune the pseudo-terminals it opens. The path to stty is hardcoded in expect itself (or in libexpect). The above suggests that expect has not been compiled properly on your system as it expects to find stty in /usr/local/bin where it obviously isn't. > 3004-687 User "0" does not exist. [...] > passwd_chng () > { > # These two echo's return correct values. but how to get expect to use > them??? > echo ${1} > echo ${2} > RET_0=$(/usr/local/bin/expect -c " > set PASSWORD [lindex $argv 1] > spawn passwd [lindex $argv 0] > expect "password:" > send "$PASSWORD\r" > expect "password:" > send "$PASSWORD\r" > expect eof > ") You're messing up with quotes and are not passing any argument to expect. You can't pass arguments with -c, but you can use environment variables. RET_0=$( USER=$1 PASSWORD=$2 /usr/local/bin/expect -c ' spawn passwd $env(USER) expect "password:" send "$env(PASSWORD)\r" expect "password:" send "$env(PASSWORD)\r" expect eof ' ) -- Stéphane |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On Jul 27, 3:04 pm, Stephane CHAZELAS <this.addr...@is.invalid> wrote:
> 2007-07-27, 04:01(-07), relikwie: > > > Hi, > > > I'm trying to create a script to automate user account creation on two > > machines. > > I use expect to handle passwd input. At this first stage (changing > > password locally) > > I have difficulty. > > You may not need ksh at all. expect is a TCL interpreter, and > the TCL language can certainly let you do all ksh can let you do > (it can invoke ksh anyway in any case). > > [...] > > > end: spawn id exp4 not open > > while executing > > "send r" > > -> spawn passwd 0 > > sh: /usr/local/bin/stty: not found. > > expect runs the stty command to tune the pseudo-terminals it > opens. The path to stty is hardcoded in expect itself (or in > libexpect). The above suggests that expect has not been compiled > properly on your system as it expects to find stty in > /usr/local/bin where it obviously isn't. I've downloaded a precompiled binary for AIX 5.2. But could create a softlink pointing the stty binary. Although the warning, the passwd succseeds. > > > > > > > 3004-687 User "0" does not exist. > [...] > > passwd_chng () > > { > > # These two echo's return correct values. but how to get expect to use > > them??? > > echo ${1} > > echo ${2} > > RET_0=$(/usr/local/bin/expect -c " > > set PASSWORD [lindex $argv 1] > > spawn passwd [lindex $argv 0] > > expect "password:" > > send "$PASSWORD\r" > > expect "password:" > > send "$PASSWORD\r" > > expect eof > > ") > > You're messing up with quotes and are not passing any argument > to expect. > > You can't pass arguments with -c, but you can use environment > variables. > > RET_0=$( > USER=$1 PASSWORD=$2 /usr/local/bin/expect -c ' > spawn passwd $env(USER) > expect "password:" > send "$env(PASSWORD)\r" > expect "password:" > send "$env(PASSWORD)\r" > expect eof > ' > ) > Stephane, reading your reaction I realize im only messing around. No background on how things really relate and work. In fact the expect bit was copy and paste, trying to get it to work. Your suggestion worked flawlessly. Have only a issue with setting the users passwd remotely. There I adjusted your lines to this: RET_0=$( log_user 0 _USER_0=${1} _PASSWORD_0=${2} /usr/local/bin/expect -c ' spawn rsh host2 passwd $env(_USER_0) expect "password:" send "$env(_PASSWORD_0)\r" expect "password:" send "$env(_PASSWORD_0)\r" expect eof ' ) This error occurs: send: spawn id exp4 not open while executing "send "$env(_PASSWORD_0)\r"" |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
2007-07-27, 08:05(-07), relikwie:
[...] > Your suggestion worked flawlessly. > Have only a issue with setting the users passwd remotely. > There I adjusted your lines to this: > > RET_0=$( > log_user 0 > _USER_0=${1} _PASSWORD_0=${2} /usr/local/bin/expect -c ' > spawn rsh host2 passwd $env(_USER_0) > expect "password:" > send "$env(_PASSWORD_0)\r" > expect "password:" > send "$env(_PASSWORD_0)\r" > expect eof > ' > ) > > This error occurs: > send: spawn id exp4 not open > while executing > "send "$env(_PASSWORD_0)\r"" It suggests that the rsh command terminated at the time expect did one of the "send"s. Did you try an run that command manually. Some "passwd" implementations will refuse to work if there's no terminal to ask a real user for a passwd. expect is a tool to fake that real user terminal (and fool passwd), but over rsh, there's no terminal (expect will provide *rsh* with a faked terminal, but rshd on the remote end will no provide *passwd* with a terminal). You could use rlogin instead of rsh (when rsh is invoked without a command to run, it invokes rlogin), rlogin starts a login session on the remote end with a pseudo-terminal. spawn rlogin host expec <the-prompt> send "passwd\r" expect "assword:" [...] expect <the-prompt> Also, you'll probably want to check for errors and problems. -- Stéphane |
|
![]() |
| Outils de la discussion | |
|
|