Hi,
I am in the process of RTFMs[0], but I was wondering if anyone had any
pointers.
We've set up a Linux server for students which uses NFS/NIS and Samba
to give them access to their home directories from Linux and Windows NT.
I'm writing a perl script to synchronise passwords for NIS and Samba, and
I've run into a problem using Expect.
Here's the subroutine. I'm passing in the username and new password.
sub SetPasswd {
my ($username, $passwd) = @_;
my $pobj = Expect->spawn($passwdex, $username);
die "Unable to spawn $passwdex:$!\n" unless (defined ($pobj));
$pobj->log_stdout(0);
$pobj->expect(10, "New password: ");
sleep 1;
print $pobj "$passwd\r"; ### <--- Problem here
$pobj->expect(10, "Re-enter new password: ");
print $pobj "$passwd\r"; ### <--- and here
$result = (defined ($pobj->expect(10, "successfully changed")) ?
"" : "password change failed");
$pobj->soft_close();
return $result;
}
It's taken from "Perl for System Administration" (O'Reilly). At the moment
I'm testing with the yppasswd program (so $passwdex is /usr/bin/yppasswd).
What's happening is that the spawn is occurring, but not working properly.
For one thing, I'm getting error messages relating to the lines
print $pobj "passwd\r";
which are:
print on closed filehandle Symbol::GEN0 at /usr/local/bin/sync_pass.pl line
64, <STDIN> chunk 4.
which indicates that the spawn has not been successful (and yet $pobj is
defined, otherwise the script would die at that point).
Any suggestions? Or is there an alternative way to synchronise the NIS and
Samba passwords? Perhaps by using configuring Samba to use the NIS passwords?
Just thought of that....
Thanks in advance,
Cormac.
[0] Manuals include "Uisng Samba", "Managing NFS and NIS", "Perl for System
Administration", and various other O'Reilly books... I have a veritable
shrine to O'Reilly Publishing in my office.
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!