[Gllug] non-interactive passwd
Alain Williams
addw at phcomp.co.uk
Thu May 8 15:21:55 UTC 2003
On Thu, May 08, 2003 at 04:12:14PM +0100, John Edwards wrote:
> On Thu, May 08, 2003 at 01:09:18PM +0100, Tethys wrote:
> >
> > Murray Peterson writes:
> >
> > >passwd $USER $PASSWORD or passwd $USER << echo $PASSWORD
> > >
> > >I am trying to do this on solaris and aix, but I would imagine that
> > >linux would have much the same reaction :)
> >
> > Actually no. Under Linux, it's easy because passwd accepts a --stdin
> > option to accept piped input from elsewhere:
> >
> > echo $password | passwd --stdin $user
> >
> > Solaris and AIX aren't so accomodating. You might want to try building
> > the Linux passwd on ther other OSen, and see if you can get it to work
> > that way.
> >
> > Tet
>
> Hi
> RedHat's passwd program can do stdin, but not the one in Debian (as
> of 3.0) or SuSE (as of 7.1).
Please find attached an expect script that I use to set a password.
The user 'visitor' has their password changed to $NEWPASS
Enjoy
--
Alain Williams
#include <std_disclaimer.h>
FATHERS-4-JUSTICE - Campaigning for equal rights for parents and the
best interests of our children. See http://www.fathers-4-justice.org
-------------- next part --------------
#!/usr/bin/expect -f
# SCCS: @(#)SetVisitorPassword 1.1 11/08/02 17:59:17
# A D D Williams, November 2002.
# Need lots of sleeps, this is because the passwd program will flush input,
# so if we send it too early, it won't see anything
# Stop the trace of the chat with 'passwd' from being echoed to stdout:
log_user 0
# spawn -noecho strace -o /tmp/pass passwd addw
spawn -noecho passwd visitor
set timeout 5
set newpass $env(NEWPASS)
#send_user "set 1st\n"
expect {
"word:" {
sleep 2
send "$newpass\n"
}
eof {
send_user "EOF from 'passwd' when waiting for first prompt\n"
exit
}
timeout {
send_user "Timeout from 'passwd' when waiting for first prompt\n"
exit
}
}
# send_user "set 2nd\n"
expect {
"word:" {
sleep 2
send "$newpass\n"
}
eof {
send_user "EOF from 'passwd' when waiting for second prompt\n"
exit
}
timeout {
send_user "Timeout from 'passwd' when waiting for second prompt\n"
exit
}
}
expect {
"successfully" {
# send_user "Done\n";
}
eof {
send_user "EOF from 'passwd' when waiting for confirmation of change\n"
exit
}
timeout {
send_user "Timeout from 'passwd' when waiting for confirmation of change\n"
exit
}
}
# end
More information about the GLLUG
mailing list