Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with expect

Status
Not open for further replies.

jewel464g

Technical User
Jul 18, 2001
198
US
I first asked this question in the perl forum and was told about expect. So I'm hoping someone here can help me better. I have a perl script that runs this command at the command line.

/sbin/passwd $user

where $user contains the user name, when this is run it prompts for the password, my problem is that since it doesn't return control to the program until after a password is typed in, I can't pass it the password. I was told in the perl forum that I could use expect, but I have no idea how to do that. Can anyone help? Below is my script.
Thanks,
Jewel


#!/usr/bin/perl -w

use FileHandle;

open (FILE, "smusers.txt") || die "opening smusers.txt";

my @file = <FILE>;
for($index=0; $index<@file; $index++){
$str = $file[$index];
my ($user,$password) = $str =~ /^(.*?):.*:(.*?)$/;
`/usr/sbin/adduser $user -g pop -s /bin/false`;
`/sbin/passwd $user`;
`su - $user`;
`/var/qmail/bin/maildirmake $\HOME/Maildir`;
`exit`;
$SIG{CHLD} = 'IGNORE';
}

close (FILE); #close the old file When faced with a decision, always ask, 'Which would be the most fun?'
 
This should input the password too:
Code:
open (PASSWD, &quot;|/sbin/passwd $user&quot;);
print PASSWD &quot;THE NEW PASSWORD\n&quot;;
print PASSWD &quot;THE NEW PASSWORD\n&quot;;
close (PASSWD);
I haven't tested this, but it should work. Note the two print's printing the same, I'm not sure if those could be concatenated or not. You could try though. //Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top