Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

running perl file

by bigup401 (Pilgrim)
on Nov 01, 2020 at 12:47 UTC ( [id://11123328]=perlquestion: print w/replies, xml ) Need Help??

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

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: running perl file
by Corion (Patriarch) on Nov 01, 2020 at 13:09 UTC

    What have you tried? How did it fail?

    Basically, if you want a cron job, use a cron job.

    The common problem with cron jobs is to assume that the cron job has the same environment and current working directory as an interactive session. This is not the case.

    You will need to set up your cron job to run with a defined working directory and a defined environment. The easiest approach to doing that is to call your main program through a shell script like:

    #!/bin/bash set -ae # load the environment source ~/.bash_profile source ~/.profile # Set the working directory to the directory the shell script # and Perl script live in: cd $(dirname $0) # Find the name of the Perl script: THIS_SCRIPT=$(basename $0) PERL_SCRIPT=${THIS_SCRIPT/.sh/pl} echo "Running $PERL_SCRIPT" # Launch it: exec $PERL_SCRIPT
Re: running perl file
by haj (Vicar) on Nov 01, 2020 at 13:34 UTC
    There sure is: Set up the perl script as a service process so that it runs continuously, and add an event handler for timer events. You can integrate it into systemd (or Windows services) so that it starts automatically after booting and re-starts after an error. You can, if you want, re-implement all parts of cron you consider interesting!
Re: running perl file
by stevieb (Canon) on Nov 01, 2020 at 16:27 UTC

    Automate it to do what? Run? Delete all files from disk? Remind you for the thousandth time to formulate proper questions by adding all required information?

Re: running perl file
by perlfan (Vicar) on Nov 02, 2020 at 16:33 UTC
    Yes, you can daemonize it or have a shell script that is daemonized (or runs in the foreground in a loop) that runs it based on your criteria. crond is the prescribed way to do this on *nix. If this is on Windows, there is a task scheduler that you can use (or crond itself via environments like cygwin). There is also at, but YMMV with that one - it's not the common "go to" for regularly occuring tasks these days.

    Note, you don't have to use a CPAN module to daemonize anything. Just run it as a loop in the background. Or if you wish to do it the "right way",

    1. start "parent script"
    2. set effective user id (setuid)
    3. fork child process
    4. kill parent
    The above process is useful if you're wishing to start the daemon on OS start up.
Re: running perl file
by karlgoethebier (Abbot) on Nov 03, 2020 at 09:30 UTC
    "...automate my perl script without cron..."

    Set up your alarm clock. See also.

    «The Crux of the Biscuit is the Apostrophe»

    perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

Re: running perl file
by bliako (Monsignor) on Nov 04, 2020 at 08:41 UTC

    systemctl

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-25 20:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found