Re: ¿Timeout en GPG? (Script de Bash)
Bueno, bueno, bueno, aquí está la solución.
La reenvío por si resulta de interés a alguien.
----- Forwarded message from Juantomás García <juantomas@lared.es> -----
Santiago Vila dijo:
> Si averiguas como lanzar un proceso y saber el pid cuentanoslo, me
> interesa :-)
$!
"$!" no es un smiley, es el número del proceso en backgound
;-)))) ;-))))
la shell funcionando
dime si hay algo que no entiendes ;-)
#!/bin/bash
# TMOUT=3 useless in a script
TIMELIMIT=3 # Three seconds in this instance, may be set to different
value.
PrintAnswer()
{
if [ $answer = TIMEOUT ]
then
echo $answer
else # Don't want to mix up the two instances.
echo "Your favorite veggie is $answer"
kill $! # Kills no longer needed TimerOn function running in
# background.
# $! is PID of last job running in background.
fi
}
TimerOn()
{
sleep $TIMELIMIT && kill -s 14 $$ &
# Waits 3 seconds, then sends sigalarm to script.
}
Int14Vector()
{
answer="TIMEOUT"
PrintAnswer
exit 14
}
trap Int14Vector 14
# Timer interrupt - 14 - subverted for our purposes.
echo "What is your favorite vegetable "
TimerOn
read answer
PrintAnswer
# Admittedly, this is a kludgy implementation of timed input,
# but pretty much as good as can be done with Bash.
# (Challenge to reader: come up with something better.)
# If you need something a bit more elegant...
# consider writing the application in C or C++,
# using appropriate library functions, such as 'alarm' and 'setitimer'.
exit 0
----- End forwarded message -----
Gracias, mil gracias a todos :-)
Precioso es script que me va a quedar :-)))
--
I stole all those good days, that's why they were taken away from me,
.''`. and they were replaced by the ones I deserve.
: :' : Speaker for the dead - Orson Scott Card
`. `' Proudly running Debian GNU/Linux Sid (Kernel 2.4.9)
`- www.amayita.com www.malapecora.com www.chicasduras.com
Listening to %s
Reply to: