Hi guys, I've found two nifty little scripts on these forums one which detects if the F5 key has been pressed:
and one which does a countdown:
What I'm trying to do is join these scripts together so that when my script runs, it does a countdown to 0 - once it gets to zero it calls a 'default' function I've written which uses non user specified parameter, but what I'd like is the user to be able to hit the F5 key if they like and 'stop' the countdown process - this will then call another function I've written which allows the user to input their own parameters. I can't seem to 'weld' the two scripts together however all attempts have failed mostly because I don't understand entirely how the key press script works? Does anyone see how I could do this? Cheers.
---------- Post updated at 07:38 PM ---------- Previous update was at 03:28 PM ----------
I am taking a class in UNIX and have written a script that needs to countdown from a number that is read in from the keyboard to zero. If no number is given the start of the countdown should default to 10.
I can't get this to do the default
#! /bin/sh
echo Enter a number here to countdown... (2 Replies)
How to stop the Prstat using shell script ?
because after i run the below script the thing seems to be always in loop and cannot get out till i ctrl + c, is there anything that i can add in the script to make it terminate ?
<code>
#!/bin/sh
prstat -Tc -u testing > testing.txt
</code>
... (19 Replies)
Hi,
I am writing a bash shell script. How can I tell it to stop. For example, I would like to have something similar to the following:
mike=1
if ; then
STOP THE SCRIPT
fi (3 Replies)
Hello,
I am ftping the file from one unix box to another box. This script works fine. Only problem here is, it is asking the password when ftp the file. How can i stop that. I am providing the password inside the shell script. But it is not accepting this. I need to put this script in crontab.... (5 Replies)
Script_A.sh has
echo "In am in script A"
ksh ## K-shell is invoked.
Script B.sh ## which I am writing...
./script_A.sh
echo "I am in script B"
return 0
When I run:
$> Script_B.sh
$> I am in script A
$>
Basically, on calling Script_A.sh from within Script_B.sh I have the issue of... (2 Replies)
Hi All,
I would like to develop a shell script for stop & start an application server (1-4) on Solaris box. Here are the user requirements for this task.
1. User will input the option which server they wish to stop.
2. Will clear cache files from specific location.
3. ... (1 Reply)
I have a strange problem.
I have the following in a cron to find files older than a day.
find /dir1/dir2/ ! -name . -prune -name "s*.txt" -type f -mtime +1 -exec echo {} \; | wc -w
It was working fine for the last few days now it suddenly stopped working. I can clearly see files in the... (5 Replies)
Hey - I need to write a shell script that gives a message on Fridays and a countdown on other business days. ("Today is Thursday, one day to go to Friday") I don't know if I should be scheduling a job for friday using the crontab command? Basically i'm totally lost. Any help would be greatly... (6 Replies)
Hi folks,
I am running a shell script it asks for username and password to stop some service, I need to write some script that it will read username and password from my shell script and then sucessfully stop services without prompting username/password query. (13 Replies)
I am writing a bash shell script for GarazLab's "WP EMAIL CRAWLER - AUTO SCRAPER & REAL TIME EXTRACTOR". it contains some commands. I want to stop the shell execution as soon as it encounters an error. how to do it? (8 Replies)
Discussion started by: tahsin352
8 Replies
LEARN ABOUT DEBIAN
io::async::timer::countdown
IO::Async::Timer::Countdown(3pm) User Contributed Perl Documentation IO::Async::Timer::Countdown(3pm)NAME
"IO::Async::Timer::Countdown" - event callback after a fixed delay
SYNOPSIS
use IO::Async::Timer::Countdown;
use IO::Async::Loop;
my $loop = IO::Async::Loop->new;
my $timer = IO::Async::Timer::Countdown->new(
delay => 10,
on_expire => sub {
print "Sorry, your time's up
";
$loop->stop;
},
);
$timer->start;
$loop->add( $timer );
$loop->run;
DESCRIPTION
This subclass of IO::Async::Timer implements one-shot fixed delays. The object implements a countdown timer, which invokes its callback
after the given period from when it was started. After it has expired the Timer may be started again, when it will wait the same period
then invoke the callback again. A timer that is currently running may be stopped or reset.
For a "Timer" object that repeatedly runs a callback at regular intervals, see instead IO::Async::Timer::Periodic. For a "Timer" that
invokes its callback at a fixed time in the future, see IO::Async::Timer::Absolute.
EVENTS
The following events are invoked, either using subclass methods or CODE references in parameters:
on_expire
Invoked when the timer expires.
PARAMETERS
The following named parameters may be passed to "new" or "configure":
on_expire => CODE
CODE reference for the "on_expire" event.
delay => NUM
The delay in seconds after starting the timer until it expires. Cannot be changed if the timer is running. A timer with a zero
delay expires "immediately".
remove_on_expire => BOOL
Optional. If true, remove this timer object from its parent notifier or containing loop when it expires. Defaults to false.
Once constructed, the timer object will need to be added to the "Loop" before it will work. It will also need to be started by the "start"
method.
METHODS
$expired = $timer->is_expired
Returns true if the Timer has already expired.
$timer->reset
If the timer is running, restart the countdown period from now. If the timer is not running, this method has no effect.
EXAMPLES
Watchdog Timer
Because the "reset" method restarts a running countdown timer back to its full period, it can be used to implement a watchdog timer. This
is a timer which will not expire provided the method is called at least as often as it is configured. If the method fails to be called, the
timer will eventually expire and run its callback.
For example, to expire an accepted connection after 30 seconds of inactivity:
...
on_accept => sub {
my ( $newclient ) = @_;
my $watchdog = IO::Async::Timer::Countdown->new(
delay => 30,
on_expire => sub {
my $self = shift;
my $stream = $self->parent;
$stream->close;
},
);
my $stream = IO::Async::Stream->new(
handle => $newclient,
on_read => sub {
my ( $self, $buffref, $eof ) = @_;
$watchdog->reset;
...
},
on_closed => sub {
$watchdog->stop;
},
) );
$stream->add_child( $watchdog );
$watchdog->start;
$loop->add( $watchdog );
}
Rather than setting up a lexical variable to store the Stream so that the Timer's "on_expire" closure can call "close" on it, the
parent/child relationship between the two Notifier objects is used. At the time the Timer "on_expire" closure is invoked, it will have been
added as a child notifier of the Stream; this means the Timer's "parent" method will return the Stream Notifier. This enables it to call
"close" without needing to capture a lexical variable, which would create a cyclic reference.
Fixed-Delay Repeating Timer
The "on_expire" event fires a fixed delay after the "start" method has begun the countdown. The "start" method can be invoked again at some
point during the "on_expire" handling code, to create a timer that invokes its code regularly a fixed delay after the previous invocation
has finished. This creates an arrangement similar to an IO::Async::Timer::Periodic, except that it will wait until the previous invocation
has indicated it is finished, before starting the countdown for the next call.
my $timer = IO::Async::Timer::Countdown->new(
delay => 60,
on_expire => sub {
my $self = shift;
start_some_operation(
on_complete => sub { $self->start },
);
},
);
$timer->start;
$loop->add( $timer );
This example invokes the "start_some_operation" function 60 seconds after the previous iteration has indicated it has finished.
AUTHOR
Paul Evans <leonerd@leonerd.org.uk>
perl v5.14.2 2012-10-24 IO::Async::Timer::Countdown(3pm)