Anonymous Monk 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.

Replies are listed 'Best First'.
Re: Execute perl script on a webserver
by Corion (Patriarch) on Sep 09, 2013 at 08:18 UTC

    If running your script only once a minute is OK, I would run the script as a cron job once every minute instead. This is the common approach to run recurring tasks and there already is lots of supporting infrastructure (and the usual problems are also well known and well documented). If you need a frequency higher than once every minute, consider letting your script run three or four checks and a pause of 10 seconds in between.

    If you want to launch a script on the remote server and have it run disconnected, the easiest approach (outside of cron) is to run it via nohup:

    nohup ./myscript.pl &
Re: Execute perl script on a webserver
by Anonymous Monk on Sep 09, 2013 at 16:50 UTC

    I would be carful to ensure only one instance of this script will be running "it will be running an "endless loop"". If this script will be facing the open internet people might trigger this script until the server's processor is over worked.

Re: Execute perl script on a webserver
by virtuemart2 (Novice) on Sep 09, 2013 at 08:25 UTC
    thanks for the nohup if I would like to use corn job, could you please tell more detail?

    reference http://www.markus-gattol.name/ws/time.html#cron

      Have you read the reference you linked? Maybe you want to talk about this with your system administrator?