Click here to get back home

How to monitor keyboard inactivity from script

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
How to monitor keyboard inactivity from script mmccaws2 04-02-2008
Posted by mmccaws2 on April 2, 2008, 12:11 pm
Please log in for more thread options
I have a user interface script that makes changes in a db or makes db
queries. I don't want the user to just leave the script running all
the time. what is the best way to monitor if the script has had no
actiivty for 20 minutes?

Thanks

Mike

Posted by jjcassidy on April 2, 2008, 12:22 pm
Please log in for more thread options
> I have a user interface script that makes changes in a db or makes db
> queries. =A0I don't want the user to just leave the script running all
> the time. =A0what is the best way to monitor if the script has had no
> actiivty for 20 minutes?
>
> Thanks
>
> Mike

You'd need to use *some kind* of persistence. Cheapest NIX-ish way is
to have a dummy file that you "touch" when you exit the program--or
whenever a significant event occurs, if you occasionally "sleep". If
you "stat" the file, you know how long it's been since it's been
"touch-ed".

Other than that, it's your choice of persistence: write and read time
to and from a file; use Storable or YAML to dump a hash with all the
values you care about; use a database....

Posted by mmccaws2 on April 2, 2008, 3:07 pm
Please log in for more thread options
On Apr 2, 9:22 am, jjcass...@gmail.com wrote:
>
> > I have a user interface script that makes changes in a db or makes db
> > queries. I don't want the user to just leave the script running all
> > the time. what is the best way to monitor if the script has had no
> > actiivty for 20 minutes?
>
> > Thanks
>
> > Mike
>
> You'd need to use *some kind* of persistence. Cheapest NIX-ish way is
> to have a dummy file that you "touch" when you exit the program--or
> whenever a significant event occurs, if you occasionally "sleep". If
> you "stat" the file, you know how long it's been since it's been
> "touch-ed".
>
> Other than that, it's your choice of persistence: write and read time
> to and from a file; use Storable or YAML to dump a hash with all the
> values you care about; use a database....

so everytime enter is hit log it and have the same script check that
or a different script monitor it? I'm not familiar with storable or
yaml, what keyword search would I use to help narrow down the choices?

Thanks

Mike

Posted by mmccaws2 on April 2, 2008, 3:12 pm
Please log in for more thread options
> On Apr 2, 9:22 am, jjcass...@gmail.com wrote:
>
>
>
>
> > > I have a user interface script that makes changes in a db or makes db
> > > queries. I don't want the user to just leave the script running all
> > > the time. what is the best way to monitor if the script has had no
> > > actiivty for 20 minutes?
>
> > > Thanks
>
> > > Mike
>
> > You'd need to use *some kind* of persistence. Cheapest NIX-ish way is
> > to have a dummy file that you "touch" when you exit the program--or
> > whenever a significant event occurs, if you occasionally "sleep". If
> > you "stat" the file, you know how long it's been since it's been
> > "touch-ed".
>
> > Other than that, it's your choice of persistence: write and read time
> > to and from a file; use Storable or YAML to dump a hash with all the
> > values you care about; use a database....
>
> so everytime enter is hit log it and have the same script check that
> or a different script monitor it? I'm not familiar with storable or
> yaml, what keyword search would I use to help narrow down the choices?
>
> Thanks
>
> Mike

Mark

our posts crossed, I'll try that

Mike

Posted by Mark on April 2, 2008, 2:59 pm
Please log in for more thread options
> I have a user interface script that makes changes in a db or makes db
> queries. =A0I don't want the user to just leave the script running all
> the time. =A0what is the best way to monitor if the script has had no
> actiivty for 20 minutes?
>
> Thanks
>
> Mike

Perhaps this sample code (works on my Linux box but doesn't work on my
Windows XP box) may help:

use strict ;
use warnings ;

$| =3D 1 ;
my $timeout =3D 20 * 60 ; # twenty minutes

my $rin =3D '' ;
vec($rin,fileno(STDIN),1) =3D 1;
my $ein =3D $rin ;

while () {
print "waiting for input\n" ;
my $nfound =3D select(my $rout=3D$rin, undef, my $eout=3D$ein,$timeout);=

if (vec($eout,fileno(STDIN),1)) {
die "error detected on STDIN" ;
}
elsif (vec($rout,fileno(STDIN),1)) {
my $ans =3D <STDIN> ;
print "got: $ans\n" ;
}
else {
print "timed out\n" ;
}
}

Similar ThreadsPosted
Can a perl script monitor another? May 17, 2005, 2:31 pm
Re: Can I monitor the execution of a perl script September 2, 2006, 8:59 am
Can I monitor the execution of a perl script September 1, 2006, 5:50 pm
log monitor September 14, 2006, 10:04 am
How to monitor changes in a directory November 9, 2006, 5:13 pm
monitor for sleeping processes December 23, 2004, 10:03 am
Writing a system log monitor March 27, 2007, 5:45 pm
Perl to monitor server stats October 13, 2004, 11:44 am
How to monitor a process in system call October 22, 2004, 9:46 am
Monitor a Serial Port (Win2k) December 1, 2004, 2:44 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap