passwortabfrage mit timeout

dosenfleisch

dosenfleisch

Foren As
hallo,

ich benötige einen dialog mit timeout, um eine passwortabfrage zu realisieren, die wenn sie ignoriert wird, eine aktion veranlaßt.

leider konnte ich bisher keines finden. xdialog hat zwar einen timeout, aber offenbar keine passwortfunktion (***), kdialog hingegen hat diese, aber dann auch nur ohne timeout.

welcher dialog hat beide funktionen integriert?

ich habe es auch schon folgendermaßen gemacht, funktioniert aber nicht:

Code:
kdialog --password &
sleep 10
killall kdialog

so kann ich jedoch das passwort nicht auslesen.
also folgendes

Code:
pass=$(kdialog --password &)
sleep 10
killall kdialog
echo $pass

so verliert das & aber seine funktion und kdialog verhindert die weitere ausführung des scriptes.

und folgendes hat keine sternchen
Code:
if xmessage -timeout 10 Dein Passwort; then ??? ; fi

edit:
lösung gibt es inzwischen durch xdialog:
Code:
password=$(Xdialog --title "Dein Passwort bitte" --timeout 30 --password --inputbox "Passwort." 0 0 2>&1)
echo $password
 
Zuletzt bearbeitet:
Timeout für kdialog

Ich habe hier ein kleines Skript, das genau das macht, was Du brauchst. Ist zwar in perl geschrieben, es sollte aber kein Problem sein, das auch als Shell-Skript umzuschreiben
Viel Erfolg!

Michael


#!/usr/bin/perl

my $cmd = "kdialog --print-winid --msgbox \"mein Name ist Hase\" 2>/dev/null &";
open( ID, "$cmd |") or die "$!";
( my $winID = <ID>) =~ s/\D//g;
system( "( sleep 10 ; xkill -id $winID) 2>/dev/null 1>&2 &");
print "going to exit in 15 seconds\n";
sleep 15;
 
Mit der bash ganz einfach:
Code:
$ read -t 10 -s var || echo "fehler"; echo "$var eingegeben";

Gruß Wolfgang
 
[OT]
warum gibt es eigentlich keinen Manual-Eintrag für read?
wie finde ich die read-optionen raus?
[/OT]
 
Es gibt schon einen manual-Eintrag für 'read' - probier mal

Code:
man bashbuiltins
 
Code:
root@debian~ # man bashbuiltins
No manual entry for bashbuiltins
zsh: exit 16    man bashbuiltins

/edit:
Ha!
Code:
man bash | grep read
 
Zuletzt bearbeitet:
Kann es sein, dass Dir das Paket 'bash-doc' fehlt? Wie kommst Du an die Optionen Standard-Befehlen wie 'cd' oder 'test'?

P17 schrieb:
Edit:

/edit:
Ha!
Code:
man bash | grep read

Hu? Da kommt wiederum bei mir nur Müll raus:

Code:
kalle@hoppers:~> man bash | grep read
Formatiere bash(1) neu, bitte warten...
       commands read from the standard input or from a file.  Bash also incor-
       -c string If  the  -c  option  is  present, then commands are read from
                 option processing, then commands are read from  the  standard
       -v        Print shell input lines as they are read.
              Do  not  use the GNU readline library to read command lines when
              Do not read either the system-wide startup file /etc/profile  or
              ~/.bash_login, or ~/.profile.   By  default,  bash  reads  these
       --norc Do  not  read  and  execute  the  personal  initialization  file
       ters are set to the remaining arguments.  Bash reads and executes  com-
       If  any  of  the files exist but cannot be read, bash reports an error.
       active shell with the --login option, it first reads and executes  com-
       mands  from  the file /etc/profile, if that file exists.  After reading
       in  that order, and reads and executes commands from the first on
[...]

'man bash' ist außerdem nicht das gleiche wie 'man bashbuiltins'

Edit again:

Code:
read  [-ers]  [-u  fd]  [-t timeout] [-a aname] [-p prompt] [-n
       nchars] [-d delim] [name ...]
              One  line  is  read from the standard input, or from the
              file descriptor fd supplied as an  argument  to  the  -u
              option,  and  the  first  word  is assigned to the first
              name, the second word to the second  name,  and  so  on,
              with  leftover  words  and  their intervening separators
              assigned to the last name.  If  there  are  fewer  words
              read  from  the  input  stream than names, the remaining
              names are assigned empty values.  The characters in  IFS
              are  used  to  split the line into words.  The backslash
              character (\) may be used to remove any special  meaning
              for  the  next character read and for line continuation.
              Options, if supplied, have the following meanings:
              -a aname
                     The words are assigned to sequential  indices  of
                     the  array  variable aname, starting at 0.  aname
                     is unset before  any  new  values  are  assigned.
                     Other name arguments are ignored.
              -d delim
                     The first character of delim is used to terminate
                     the input line, rather than newline.
              -e     If the standard input is coming from a  terminal,
                     readline  (see  READLINE above) is used to obtain
                     the line.
              -n nchars
                     read  returns  after  reading  nchars  characters
                     rather than waiting for a complete line of input.
              -p prompt
                     Display  prompt  on  standard  error,  without  a
                     trailing  newline,  before attempting to read any
                     input.  The prompt is displayed only if input  is
                     coming from a terminal.
              -r     Backslash  does  not  act as an escape character.
                     The backslash is considered to  be  part  of  the
                     line.   In  particular,  a backslash-newline pair
                     may not be used as a line continuation.
              -s     Silent mode.  If input is coming from a terminal,
                     characters are not echoed.
              -t timeout
                     Cause  read  to  time out and return failure if a
                     complete line of input is not read within timeout
                     seconds.   This  option  has no effect if read is
                     not reading input from the terminal or a pipe.
              -u fd  Read input from file descriptor fd.

If no names are supplied, the line read is  assigned  to
              the  variable  REPLY.   The  return code is zero, unless
              end-of-file  is  encountered,  read  times  out,  or  an
              invalid  file  descriptor is supplied as the argument to
              -u.
 
Zuletzt bearbeitet:
read ist in der man bash.
Ein grep auf read bringt den berümten Feuerwehrschlauch für den Verdurstenden, weil read in vielen Sätzen vorkommt.

Kannst es ja mal so versuchen:
Code:
$ man bash|grep -A50 '^[[:space:]]*read[[:space:]]*\['

;)
Gruß Wolfgang
 
read ist in der man bash.
Ein grep auf read bringt den berümten Feuerwehrschlauch für den Verdurstenden, weil read in vielen Sätzen vorkommt.

Kannst es ja mal so versuchen:
Code:
$ man bash|grep -A50 '^[[:space:]]*read[[:space:]]*\['

;)
Gruß Wolfgang

Vielen Dank!
Code:
man bash|grep -A50 '^[[:space:]]*read[[:space:]]*\[' > manpages/read.txt
:D
 
Es soll auch Distributionen geben, wo das ohne Gefummel geht:

Code:
man read
Formatiere bashbuiltins(1) neu, bitte warten...

Tatsächlich :devil:
 
Und folgendes sollte auf allen Distributionen für alle bash-builtins funktionieren:

Code:
help read

ergibt:

read: read [-ers] [-u fd] [-t timeout] [-p prompt] [-a array] [-n nchars] [-d delim] [name ...]
One line is read from the standard input, or from file descriptor FD if the
-u option is supplied, and the first word is assigned to the first NAME,
the second word to the second NAME, and so on, with leftover words assigned
to the last NAME. Only the characters found in $IFS are recognized as word
delimiters. If no NAMEs are supplied, the line read is stored in the REPLY
variable. If the -r option is given, this signifies `raw' input, and
backslash escaping is disabled. The -d option causes read to continue
until the first character of DELIM is read, rather than newline. If the -p
option is supplied, the string PROMPT is output without a trailing newline
before attempting to read. If -a is supplied, the words read are assigned
to sequential indices of ARRAY, starting at zero. If -e is supplied and
the shell is interactive, readline is used to obtain the line. If -n is
supplied with a non-zero NCHARS argument, read returns after NCHARS
characters have been read. The -s option causes input coming from a
terminal to not be echoed.

The -t option causes read to time out and return failure if a complete line
of input is not read within TIMEOUT seconds. If the TMOUT variable is set,
its value is the default timeout. The return code is zero, unless end-of-file
is encountered, read times out, or an invalid file descriptor is supplied as
the argument to -u.
readonly: readonly [-af] [name[=value] ...] or readonly -p
The given NAMEs are marked readonly and the values of these NAMEs may
not be changed by subsequent assignment. If the -f option is given,
then functions corresponding to the NAMEs are so marked. If no
arguments are given, or if `-p' is given, a list of all readonly names
is printed. The `-a' option means to treat each NAME as
an array variable. An argument of `--' disables further option
processing.

Siehe

help help
help: help [-s] [pattern ...]
Display helpful information about builtin commands. If PATTERN is
specified, gives detailed help on all commands matching PATTERN,
otherwise a list of the builtins is printed. The -s option
restricts the output for each builtin command matching PATTERN to
a short usage synopsis.

......:devil:
 
Very nice.

Wobei ich mir immer noch nicht vorstellen kann, wieso das unter Debian mit dem automatischen Öffnen der passenden man-Page über "man read" nicht funktionieren soll.

Greetz,

RM
 
@tomuschat

danke dir.
inzwischen mache ich es so, daß ich vor der passwortabfrage ein zusätzliches script starte, daß den kdialog nach einiger zeit schließt.
also im prinzip so wie bei dir.
 
@Rain_Maker: Du meinst so:
Code:
man read
Formatiere read(2) neu, bitte warten...

Hm, dann ist mein Debian wohl kaputt, wenn das bei mir geht? :D
 
@Rain_Maker: Du meinst so:
Code:
man read
Formatiere read(2) neu, bitte warten...

Hätte mich jetzt auch schwer gewundert.

Hm, dann ist mein Debian wohl kaputt, wenn das bei mir geht? :D

*HRHRHR*

Und als Würgaround, um sein Debian genau so "kaputt" zu bekommen, muß man wahrscheinlich

Code:
apt-get remove --purge PEBKAC
ausführen (optional dürfte es auch mit aptitude klappen *g*)

Greetz,

RM
 
@Rain_Maker: Du meinst so:
Code:
man read
Formatiere read(2) neu, bitte warten...

Hm, dann ist mein Debian wohl kaputt, wenn das bei mir geht? :D

Dabei musst du aber berücksichtigen, dass du nicht die man-page für das Bash-Builtin read (um das es hier geht), sondern für die Funktion read() aufrufst. Ich musste bisher unter Ubuntu auch immer die bash man-page aufschlagen, wenn ich Informationen über einen eingebauten Befehl brauchte. Allerdings habe ich herausgefunden, dass bei mir
Code:
man bash-builtins
funktioniert, um direkt zu der man-page der Bash-Befehle zu gelangen.

Gruß,
Philip
 
Zuletzt bearbeitet:
Hm, anhand der Ausgabe bei mir

Code:
Formatiere bashbuiltins[B](1)[/B] neu, bitte warten...
könnte man es mal mit

Code:
man 1 read
versuchen.

(ggf. nachsehen, ob bash-builtins auch in man1 liegt, ansonsten anpassen)

Wobei die in Post 11 gezeigte Alternative noch einen Tick eleganter wäre.

//Edit:

Bei mir geht das

Code:
man read
Formatiere bashbuiltins[B](1)[/B] neu, bitte warten...

man 1 read
Formatiere bashbuiltins[B](1)[/B] neu, bitte warten...

man 2 read
Formatiere read[B](2)[/B] neu, bitte warten...

(openSUSE 10.2)

Greetz,

RM
 
Zuletzt bearbeitet von einem Moderator:
[...]könnte man es mal mit

Code:
man 1 read
versuchen.

Habe ich schon versucht. Ich habe auch noch das Paket bash-doc installiert (wie von gropiuskalle vorgeschlagen), aber trotzdem gibt es bei mir (Ubuntu 7.04) nur die read manpage in Sektion 2:
Code:
$ apropos -r ^read$
read (2)             - read from a file descriptor

Allerdings ist der Tipp von supersucker (Post 11) gut, obwohl es mir bisher auch nichts ausgemacht hat in der bash manpage nachzuschauen.

Gruß,
Philip
 
lösung für das eigentliche problem gibt es inzwischen durch xdialog:
Code:
password=$(Xdialog --title "Dein Passwort bitte" --timeout 30 --password --inputbox "Passwort." 0 0 2>&1)
echo $password
 
Zurück
Oben