Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Execute a script on a server

by Sietsch (Initiate)
on Sep 09, 2013 at 08:18 UTC ( [id://1052974]=perlquestion: print w/replies, xml ) Need Help??

Sietsch has asked for the wisdom of the Perl Monks concerning the following question:

Hi there

Until now, I have used perl mainly to work with local files and databases.
For my current project, I want to have my script running on a webserver since it will be running an "endless loop". In other words, the script checks for something every 10 seconds and therefore, executing it on a server makes sense.
My question: How do I execute a perl script on a server and keep it running? Simply via SSH using the "&" to fork the process?

Thanks for your help.
EDIT:
Looks like this has to be done as CGI or CRON. Right?

Replies are listed 'Best First'.
Re: Execute a script on a server
by daxim (Curate) on Sep 09, 2013 at 10:09 UTC
Re: Execute a script on a server
by karlgoethebier (Abbot) on Sep 09, 2013 at 17:43 UTC

    Wasn't this the classic?

    #!/usr/bin/env perl use POSIX qw(setsid); print daemonize(); sub daemonize { my $child = fork; if ( definded ($child) ) { exit 0 ; } else { die qq(I really can't...!\n); } setsid(); open( STDIN, "</dev/null" ); open( STOUT, ">/dev/null" ); open( STDIN, ">&STDOUT" ); chdir '/'; umask(0); ENV{PATH}=q(/what/you/like); return $$; }

    Please see also Parallel::ForkManager.

    Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1052974]
Approved by Athanasius
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-19 23:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found