I am specifically needing:
$ENV{DOCUMENT_ROOT}
$ENV{SERVER_NAME}
$ENV{SERVER_ADMIN}
and the current script directory which is usually the default if no other prefix is provided when accessing a filename.
How does one avoid hard-coding all those entries that $ENV{} makes available?
* * * * * wget [mydomain.com...] > /dev/null 2>&1
* * * * * wget [mydomain.com...] >> /path/to/log.txt 2>&1
If you wanted to send an email to $ENV{SERVER_ADMIN}, this would have to be done within the perl script, because it has access to those environmental variables.
However, I'm also getting a bunch of wget messages and menu text in the log in addition to just the expected "Done" from my script and according to [weather.ou.edu...] there should also be a cron option for automatic email notification but the one time that I even came close to getting the cron to run previously I got "No recipient addresses found in header".
Any ideas on how to suppress the wget messages and also, what header?
wget [mydomain.com...] -O /path/to/log.txt > /dev/null 2>&1
As far as cron automatically emailing, if the cron job generates any output, it will email the results to the user on the current server. So if your webserver is also your mail server, or it is setup to forward email to your mail server, and the username is the same as your email, then you should receive a message. You could also add an extra command to send an email to any address, something like:
* * * * * wget [mydomain.com...] -O /path/to/log.txt > /dev/null 2>&1; cat /path/to/log.txt ¦ mail -s "cron notification" WWMike@mikesemail.com
I dabble in PERL but I drown in UNIX and I don't have access to a UNIX prompt so for testing purposes, I brute-forced a quickie PERL script to simulate the bulk of the CRON command <wink>:
#!/usr/local/bin/perl
system("/usr/local/bin/wget -q -O - [mydomain.com...] >> /usr/home/myaccount/scripts/mydomain.com/script/log.txt");
print "Content-type: text/html\n\n";
exit;
OK, here's a quick summary for review:
I need to use wget to run my script because my script needs the PERL $ENV{} variables but UNIX CRON doesn't provide them.
The -q tells wget to be quiet and supress its (useless) messages while the -O - tells wget to send the script output to STDOUT instead of writing it to a file (which is the wget default).
I should also mention that according to the wget docs at [gnu.org...] there doesn't seem to be an option to have wget append the script output so I have to resort to redirecting it with the UNIX >>.
2 questions:
1) Why doesn't the UNIX >> append to the log file?
It creates it if it doesn't exist but it always overwrites it after that and I can't seem to get a running log.
And also...
2) Why do I have to include the print to eliminate the 500 error I get without it?
My host swears that the system logs prove that CRON ran only once per day as should be the case but somehow my script ran 6 times within 3 minutes today and 2 times within 1 minute a couple of days ago.
There is absolutely no way that my script could be looping or running itself more than once and if I trust my host to be correct then that leaves wget as the sole culprit.
Anyone have any previous experience with this type of issue?
[mydomain.com...]
but on closer inspection that looks like a dummy URL.
The return value is the exit status of the program as returned by the wait() call. To get the actual exit value divide by 256. See also exec. This is NOT what you want to use to capture the output from a command, for that you should use merely backticks or qx//, as described in `STRING`.
If you omit the print statement after the system call, there is no output. The 500 error results from making a CGI web request that produces no output.