Hi, I didn't work with Perl for ages but recently I needed it for a small task. So basically the script will run once every day by a cronjob (no HTML output). It also will have some info to show when called from a browser like https://www.example.com/cgi-bin/myscript.cgi
So my question is if it is possible to reliable distinguish - inside the script - if it was called by crontab or by HTTP request (some envs or something)? It will be running at Apache.
(Update) Thank you all for your help. I eventually went by if (exists $ENV{REQUEST_URI}) {web call} else {not web call} By "some definition of "reliable" it is plenty good as I see it. Unless some sysadmin goes nuts with system configs - but it is in any case a battle one can fight but cannot win. Because if a sysadmin mangles with REQUEST_URI or GATEWAY_INTERFACE - he/she equally may install Perl to /usr/bin/foo/bar/current_day to make the shebang dynamic - or anything equally crazy. My current hosting provider is not of kind, so everything is fine.
A more bulletproof solution as I read it: to have 2 separate scripts (modules). One outside of /public_html or its equivalent so cannot be reached by a web-call (for crontab), other inside /public_html (for web access). Also some file for interscript communication and maybe some higher level script for the main business logic. The pay back for this: a violation of the KISS principle - instead of of one place where something may go wrong there will be 3-4 places where something may go wrong. And for outside of /public_html something may go really wrong. So the pay off doesn't cover the back back, IMO.
In reply to How to distinguish a crontab call and a web call by VK
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |