Hide password or Prompt for password

John G. Heim jheim at math.wisc.edu
Fri Jan 31 16:33:47 CET 2014



> Ideally, is this possible to be prompted for this password by FAI when
> installing the clients ?

You can do this by reading from  /dev/console.

Here is a perl code segment that does more than just what you're asking 
about. But you should be able to get the jist of it from this code. The 
subroutine  takes a string prompt, a hash containing the acceptable 
answers to the prompt, and a default value. It displays the choices, 
then prompts for an answer, and then checks the  answer versus the 
choices hash. If you just press enter, it takes the default value. And 
it times out after 300 seconds.  You put this code into a class script 
so it is called before  the install begins.


sub askQuestion
	{
	my $question = shift;
	my $choices = shift;
	my $default = shift;
	my $answer = '';
   if (	open CONSOLE, "</dev/console")
		{
		while (not defined ($choices->{$answer}))
			{
			eval
				{
				local $SIG{ALRM} = sub { die "alarm clock restart" };
				alarm 300;
				printf STDERR "$question\n\n" . join ("\n ", map ($_ . "=" . 
$choices->{$_}, keys %$choices)) . "\nYour choice (default=$default): ";
				$answer = <CONSOLE>;
				chomp($answer);
				alarm 0;
				}; # lave
			$answer = $default unless ($answer);
			warn "ANSWER=$answer";
			} # elihw
		close (CONSOLE);
		} # fi
	return $answer;
	} # bus AskQuestion


More information about the linux-fai mailing list