
|
View Full Version : How to get a cron job to send me an email?
traktor 03-22-2003, 12:29 PM Each morning when I come in, I find some emails waiting, reports on cron jobs the machine has done -- cpanel updates, user backups, things like this.
I've set up a separate backup of certain files as a cron job. This job runs just fine, and I successfully capture its output to a file. How can I modify the script or the cronjob to email me that output?
This is probably a simple thing, but I'm completely baffled.
Can anyone advise me, or point me to where the info can be found?
digitok 03-22-2003, 12:35 PM Well I don't use cronjobs really but I'm guessing
that you can make it run a .php file, if so, you could
make a php script that reads the output file that you
said you have, and emails it to you, then put that php
file as a cronjob? I've added you to AIM, if this would work
but you don't know how to make the php script, just go on
AIM and I will try and help you out.
traktor 03-22-2003, 05:54 PM That's an interesting approach, and one I'd not thought of.
Now, firstly, I'll bet it can be done from a shell script or perhaps from the cron job itself, but I just don't know how.
However, you've made me wonder about something else -- I've only used php to do things inside web pages. How do you run it on its own?
sorry to be so ignorant ... but I am.
ChickenSteak 03-22-2003, 06:11 PM Execute it in shell.
#!/usr/bin/php -f
<?php
print "Test\n";
?>
Please note the #!/usr/bin/php path may vary depending on where you have php installed. Then chmod it 0755. Then run it ./filename.
traktor 03-22-2003, 07:18 PM Originally posted by ChickenSteak
#!/usr/bin/php -f
<?php
print "Test\n";
?>
Please note the #!/usr/bin/php path may vary depending on where you have php installed. Then chmod it 0755. Then run it ./filename.
. . . . <stupified silence :eek: > . . . .
Oh, ChickenSteak, I bow low before your magnificance!
I have two big-ole php books, I've got an official manual with hundreds of pages printed out (version 3 though), and I have in fact done projects in php.
I never knew this! It doesn't say anything in any of my references!
Holy cow!
Now, of course, it leads me to three questions --
1. Generally I've read references suggesting that php is 'more secure' than is perl. Now would that hold true when php is run as a cgi-module (which I'm assuming it is here) or only when php is run as a module inside apache?
2. On my computer, I appear to have php installed in two places:
/usr/bin/php with a length of 4531863, and also at
/usr/local/bin/php with a length of 4528603
Neither seems to be a symlink. They both show the same creation date, which I think is when I rebuilt apache after an openssl upgrade.
There is a difference between them, however. When I run your demo program with /usr/bin/php the output is preceded by
Content-type: text/html
X-Powered-By: PHP/4.3.1
[and one blank line]
And when I run your demo program with /usr/local/bin/php the content, the X-statement, and the blank line do not appear.
Would you know why php appears to be installed in two places
3. The first thing the demo program actually spits out, is a long complaint about how it cannot find ZendOptimizer.so. Why? And how can I get rid of the complaining message?
I would be grateful if you could shed some light on these mysteries.
ChickenSteak 03-22-2003, 07:38 PM Ok to explain the two instances of the php binary one is the newest version of php, and the other is an older version. Go ahead and delete /usr/local/bin/php. As far as security perl/php comparison they're about the same. As far as zend optomizer, zend just now released support for php version 4.3.x so I would go to www.zend.com download the newest version and install zend, and the error should go away.
traktor 03-22-2003, 10:28 PM Originally posted by traktor
I've set up a separate backup of certain files as a cron job. This job runs just fine, and I successfully capture its output to a file. How can I modify the script or the cronjob to email me that output?
I'm glad I asked this question, because I learned some great new stuff about php, which I like a lot.
And -- duh -- I also learned the simple answer to my question. The answer is: don't send the cron output to a file. Then, by default, cron will email it to me, which is what I wanted in the first place.
I had entered the cronjob like this:
5 3 * * * myjobscript.sh > myjoboutput.txt
Well, because I was diverting the output, cron didn't email it to me. I've changed the cron job to:
5 3 * * * myjobscript.sh
And that should do it. Duh!
And thanks for the great new info about php. Also, anybody recommend a clear and decent book about BASH scripting?
MarlboroMan 03-23-2003, 10:45 AM I have Linux and Unix Shell Programming, published by Addison-Wesley. Not only does it cover scripting syntax, etc - it also covers your common building blocks for scripts - find, sed, awk, etc. It is a little dense though, and hard to find exactly what you are looking for.
|