On Sat, Feb 26, 2005 at 11:42:15AM +0530, raghu wrote:
> 
> I have a written a small perl script that fetches RSS feeds and
> dumps  the output  into  a html  file  residing  on the  user's
> desktop.I want  the script to call  itself and update  the html
> file periodically with  new feeds.I am new to perl  and this is
> my first  perl program.I can  use 'at'  or 'cron' (on  *nix) to
> automate the  job but I want  the script to call  itself (since
> this script might be placed on a windows machine).Google search
> is going on but  would appreciate if the group can  point me to
> some  resources on  scheduling.Alternatively,  I  can place  an
> 'update' button  in the  html file,  which will  call the  perl
> script and update itself.
> 
> Of course,  I can use  the 'at' command  or the GUI  based Task
> Scheduler in Winduhs, but would like a generic solution.
> 

Raghu, one of the ways is to run  your perl script is as a perl
'daemon' itself.

I am  placing a small script  below as an example.  This merely
puts a  time stamp every  10 seconds. Since this uses  the *nix
'date' function,  may not  work under  Winduhs, just  change to
"Hello World" or something else ;-)

---------------------------<snip>--------------------------------

#!/usr/bin/perl
use POSIX qw(setsid);

# Direct everything to /dev/null (for non-interference)
open STDIN, '/dev/null'     || die "ERR: read /dev/null: $!";
# open STDOUT, '>/dev/null' || die "ERR: write to /dev/null: $!";
open STDERR, '>/dev/null'   || die "ERR: write to /dev/null: $!";

# Exit if already running or else setsid this script
defined(my $pid = fork)     || die "ERR: Can't fork: $!";
exit if $pid;
setsid                      || die "ERR: starting new session: $!";

# Do the job (endless loop)
while(1) {
   sleep(10);
   my $tyme = `date +%H:%M:%S`;
   print "Time ... $tyme \n";
}

--------------------------</snip>---------------------------------

o Uncomment STDOUT line to suppress output. It will work in
  the background.
o POSIX library needed, since 'setsid' is not built-in perl
o Alter delay in the 'sleep' command within while loop.
o Instead of 'print bla bla ...' run your RSS script or you
  may insert that  script here (if not large).  This itself
  takes about 1k of memory. 
o You need to 'kill pid' to stop this 'daemon' !

HTH

Bish



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
linux-india-help mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-india-help

Reply via email to