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? Please keep in mind that I have never used this before and didn't even know it existed until yesterday. 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?'
/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? Please keep in mind that I have never used this before and didn't even know it existed until yesterday. 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?'