Discussion:
User abort
(too old to reply)
libtest
2006-03-05 02:57:08 UTC
Permalink
I'm trying to run a script that will run indefinitely (do some stuff,
sleep, do some stuff, sleep, ...), but still allow the admin to terminate
it at his will. How do I do that with Perl on NetWare since Ctrl+C isn't
supported?
Can I somehow combine the functionality of read and sleep so that if a
user presses a key or something during the sleep period the script will
detect it and terminate?
Randolf Richardson
2006-03-06 06:46:17 UTC
Permalink
Post by libtest
I'm trying to run a script that will run indefinitely (do some stuff,
sleep, do some stuff, sleep, ...), but still allow the admin to terminate
it at his will. How do I do that with Perl on NetWare since Ctrl+C isn't
supported?
A "quick-and-dirty" solution that I've used in the past is to program my
PERL script to periodically call a function that terminates the script if
a file exists (in this case I called the file "SYS:/script.off"). If this
is of interest to you, then here's the source code for the subroutine:

sub _shutdown_check { # --- Terminate this process if a file exists
if (-e 'SYS:/script.off') { # --- File exists
unlink 'SYS:/script.off'; # --- Delete this file
die 'File "SYS:/script.off" detected. Manual shutdown initiated.';
}
return; # --- File doesn't exist
}

So, in your loops, simply call this subroutine with no parameters. Since
it doesn't create any variables, and returns no data, it shouldn't effect
anything you're doing (be careful with subroutines that don't end with
"return" statements because they'll sometimes return unpredictable data
which can lead to bugs that are often subtle and very difficult to track
down).

Of course, the contents of the file don't matter because it will just get
deleted before your script is terminated. From any logged in workstation
(or a server application {you could even write another PERL script to
create this file}), either copy another file to SYS:/script.off when you
want to terminate your script, or just echo something to it from DOS
(assuming drive F: is mapped to your SYS: volume):

Echo The end is near...>F:script.off

I hope this helps.
Post by libtest
Can I somehow combine the functionality of read and sleep so that if a
user presses a key or something during the sleep period the script will
detect it and terminate?
I've been down this road before, and even checking the EOF state of STDIN
didn't seem to work as expected (but NetWare wasn't acting any differently
from Unix and Windows implementations in this regard). The other
functions to get one character would also just block, and that's not the
desired effect.

Perhaps things have improved, but I haven't had a need to look into this
for many years now.
--
Randolf Richardson - ***@inter-corporate.com
Inter-Corporate Computer & Network Services, Inc.
Vancouver, British Columbia, Canada
http://www.inter-corporate.com/

This message originated from within a secure, reliable,
high-performance network ... a Novell NetWare network.
Continue reading on narkive:
Loading...