Cron command help

Soldato
Joined
12 Jan 2004
Posts
6,824
Location
Londinium
I have a cron job that runs every 15 minutes that runs a php script which broadcasts any email campaigns that have been scheduled. The command is:

Code:
lynx -dump http://www.*******.co.uk/scripts/broadcast.php

It works fine, but the only problem is that I am emailed the output everytime the script runs. You can imagine that they can build up being sent every 15 mins of every day! The emails are almost always blank as the script runs with no errors. However, what I would really like is to only be emailed when an error has occured, and so the cron output would not be blank. Is there anyway to modify the cron job command to make this happen?
 
Pine said:
You need to redirect the script output to /dev/null. Have a look at the crontab article on Wikipedia.

So the command would be:

Code:
lynx -dump http://www.*******.co.uk/scripts/broadcast.php >/dev/null 2>&1

But wont that stop all email output? I still want to be emailed when an error occurs, just not when no error occurs.
 
Code:
lynx -dump [url]http://www.*******.co.uk/scripts/broadcast.php[/url] 1> /dev/null

Try that.

edit: Actually, I doubt that would work, do you have access to the php command line program thingy?
 
Last edited:
Pine said:
Code:
lynx -dump [url]http://www.*******.co.uk/scripts/broadcast.php[/url] 1> /dev/null

Try that.

edit: Actually, I doubt that would work, do you have access to the php command line program thingy?

Well its just the standard cpanel thing for my web host (tsohost), so I doubt it.
 
Pine said:
Give it a bash:

Code:
php -f /home/you/path/to/file.php 1> /dev/null

Okay it seems to work i.e. not sending me emails when they are no errors. But, I changed the username of the db connection line in the script to force an error, and this is what I got mailed:

Code:
*** glibc detected *** php: double free or corruption (!prev): 0x0000000000a42310 ***
======= Backtrace: =========
/lib64/libc.so.6[0x3c14f6ae4f]
/lib64/libc.so.6(__libc_free+0x6e)[0x3c14f6b38e]
php(destroy_zend_class+0x62)[0x56f322]
php(zend_hash_destroy+0x38)[0x57ac08]
php(zend_shutdown+0x4d)[0x57618d]
php(php_module_shutdown+0x25)[0x549d75]
php(main+0x4b0)[0x593170]
/lib64/libc.so.6(__libc_start_main+0xef)[0x3c14f1c40f]
php[0x433fb9]
======= Memory map: ========
00400000-00738000 r-xp 00000000 08:02 7089046                            /usr/bin/php
00837000-00898000 rw-p 00337000 08:02 7089046                            /usr/bin/php
00898000-008b5000 rw-p 00898000 00:00 0 
00997000-009a9000 rw-p 00397000 08:02 7089046                            /usr/bin/php
009a9000-00ba7000 rw-p 009a9000 00:00 0                                  [heap]
37a2d00000-37a2e29000 r-xp 00000000 08:02 7087294                       
/usr/lib64/libxml2.so.2.6.22
37a2e29000-37a2f28000 ---p 00129000 08:02 7087294                       
/usr/lib64/libxml2.so.2.6.22
37a2f28000-37a2f35000 rw-p 00128000 08:02 7087294                       
/usr/lib64/libxml2.so.2.6.22
37a2f35000-37a2f36000 rw-p 37a2f35000 00:00 0 
37a3000000-37a3032000 r-xp 00000000 08:02 7087069                       
/usr/lib64/libxslt.so.1.1.8
37a3032000-37a3131000 ---p 00032000 08:02 7087069                       
/usr/lib64/libxslt.so.1.1.8
37a3131000-37a3133000 rw-p 00031000 08:02 7087069                       
/usr/lib64/libxslt.so.1.1.8
37a3200000-37a3237000 r-xp 00000000 08:02 7087437                       
/usr/lib64/libcurl.so.3.0.0
37a3237000-37a3337000 ---p 00037000 08:02 7087437                       
/usr/lib64/libcurl.so.3.0.0
37a3337000-37a3339000 rw-p 00037000 08:02 7087437                       
/usr/lib64/libcurl.so.3.0.0
37a3400000-37a34c2000 r-xp 00000000 08:02 7087413                       
/usr/lib64/libsablot.so.0.100.1
37a34c2000-37a35c1000 ---p 000c2000 08:02 7087413                       
/usr/lib64/libsablot.so.0.100.1
37a35c1000-37a35ca000 rw-p 000c1000 08:02 7087413                       
/usr/lib64/libsablot.so.0.100.1
37a3600000-37a360f000 r-xp 00000000 08:02 7087403                       
/usr/lib64/libexslt.so.0.8.6
37a360f000-37a370f000 ---p 0000f000 08:02 7087403                       
/usr/lib64/libexslt.so.0.8.6
37a370f000-37a3710000 rw-p 0000f000 08:02 7087403                       
/usr/lib64/libexslt.so.0.8.6
37a3800000-37a382e000 r-xp 00000000 08:02 7087398                       
/usr/lib64/libmcrypt.so.4.4.7
37a382e000-37a392d000 ---p 0002e000 08:02 7087398                       
/usr/lib64/libmcrypt.so.4.4.7
37a392d000-37a3931000 rw-p 0002d000 08:02 7087398                       
/usr/lib64/libmcrypt.so.4.4.7
37a3931000-37a3937000 rw-p 37a3931000 00:00 0 
3a45e00000-3a45eda000 r-xp 00000000 08:02 7089377                       
/usr/X11R6/lib64/libX11.so.6.2
3a45eda000-3a45fd9000 ---p 000da000 08:02 7089377                       
/usr/X11R6/lib64/libX11.so.6.2
3a45fd9000-3a45fdf000 rw-p 000d9000 08:02 7089377                       
/usr/X11R6/lib64/libX11.so.6.2
3a46000000-3a46010000 r-xp 00000000 08:02 7084960                       
/usr/X11R6/lib64/libXext.so.6.4
3a46010000-3a46110000 ---p 00010000 08:02 7084960                       
/usr/X11R6/lib64/libXext.so.6.4
3a46110000-3a46111000 rw-p 00010000 08:02 7084960                       
/usr/X11R6/lib64/libXext.so.6.4
3a46200000-3a46248000 r-xp 00000000 08:02 7087588                       
/usr/lib64/libmysqlclient.so.14.0.0
3a46248000-3a46348000 ---p 00048000 08:02 7087588                       
/usr/lib64/libmysqlclient.so.14.0.0
3a46348000-3a46428000 rw-p 00048000 08:02 7087588                       
/usr/lib64/libmysqlclient.so.14.0.0
3a46428000-3a46429000 rw-p 3a46428000 00:00 0 
3a46800000-3a46816000 r-xp 00000000 08:02 7084948                       
/usr/X11R6/lib64/libXpm.so.4.11
3a46816000-3a46915000 ---p 00016000 08:02 7084948                       
/usr/X11R6/lib64/libXpm.so.4.11
3a46915000-3a46916000 rw-p 00015000 08:02 7084948                       
/usr/X11R6/lib64/libXpm.so.4.11
3c14d00000-3c14d1a000 r-xp 00000000 08:02 5701641                       
/lib64/ld-2.3.6.so
3c14e19000-3c14e1a000 r--p 00019000 08:02 5701641                       
/lib64/ld-2.3.6.so
3c14e1a000-3c14e1b000 rw-p 0001a000 08:02 5701641                       
/lib64/ld-2.3.6.so
3c14f00000-3c1502e000 r-xp 00000000 08:02 5701645                       
/lib64/libc-2.3.6.so
3c1502e000-3c1512d000 ---p 0012e000 08:02 5701645                       
/lib64/libc-2.3.6.so
3c1512d000-3c15131000 r--p 0012d000 08:02 5701645                       
/lib64/libc-2.3.6.so
3c15131000-3c15133000 rw-p 00131000 08:02 5701645                       
/lib64/libc-2.3.6.so
3c15133000-3c15137000 rw-p 3c15133000 00:00 0 
3c15200000-3c15202000 r-xp 00000000 08:02 5701677                       
/lib64/libdl-2.3.6.so
3c15202000-3c15302000 ---p 00002000 08:02 5701677                       
/lib64/libdl-2.3.6.so
3c15302000-3c15303000 r--p 00002000 08:02 5701677                       
/lib64/libdl-2.3.6.so
3c15303000-3c15304000 rw-p 00003000 08:02 5701677                       
/lib64/libdl-2.3.6.so
3c15400000-3c15484000 r-xp 00000000 08:02 5701685                       
/lib64/libm-2.3.6.so
3c15484000-3c15584000 ---p 00084000 08:02 5701685                       
/lib64/libm-2.3.6.so
3c15584000-3c15585000 r--p 00084000 08:02 5701685                       
/lib64/libm-2.3.6.so
3c15585000-3c15586000 rw-p 00085000 08:02 5701685                       
/lib64/libm-2.3.6.so
3c15600000-3c15614000 r-xp 00000000 08:02 7084438                       
/usr/lib64/libz.so.1.2.2.2
3c15614000-3c15713000 ---p 00014000 08:02 7084438                       
/usr/lib64/libz.so.1.2.2.2
3c15713000-3c15714000 rw-p 00013000 08:02 7084438                       
/usr/lib64/libz.so.1.2.2.2
3c15800000-3c15811000 r-xp 00000000 08:02 5701663                       
/lib64/libresolv-2.3.6.so
3c15811000-3c15911000 ---p 00011000 08:02 5701663                       
/lib64/libresolv-2.3.6.so
3c15911000-3c15912000 r--p 00011000 08:02 5701663                       
/lib64/libresolv-2.3.6.so
3c15912000-3c15913000 rw-p 00012000 08:02 5701663                       
/lib64/libresolv-2.3.6.so
3c15913000-3c15915000 rw-p 3c15913000 00:00 0 
3c15a00000-3c15a21000 r-xp 00000000 08:02 7085251                       
/usr/lib64/libjpeg.so.62.0.0
3c15a21000-3c15b21000 ---p 00021000 08:02 7085251                       
/usr/lib64/libjpeg.so.62.0.0
3c15b21000-3c15b22000 rw-p 00021000 08:02 7085251                       
/usr/lib64/libjpeg.so.62.0.0
3c15c00000-3c15c05000 r-xp 00000000 08:02 5701746                       
/lib64/libcrypt-2.3.6.so
3c15c05000-3c15d04000 ---p 00005000 08:02 5701746                       
/lib64/libcrypt-2.3.6.so
3c15d04000-3c15d05000 r--p 00004000 08:02 5701746                       
/lib64/libcrypt-2.3.6.so
3c15d05000-3c15d06000 rw-p 00005000 08:02 5701746                       
/lib64/libcrypt-2.3.6.so
3c15d06000-3c15d34000 rw-p 3c15d06000 00:00 0 
3c16000000-3c16002000 r-xp 00000000 08:02 5701689                       
/lib64/libcom_err.so.2.1
3c16002000-3c16101000 ---p 00002000 08:02 5701689                       
/lib64/libcom_err.so.2.1
3c16101000-3c16102000 rw-p 00001000 08:02 5701689                       
/lib64/libcom_err.so.2.1
3c16200000-3c16202000 r-xp 00000000 08:02 7081092                       
/usr/lib64/libkrb5support.so.0.0
3c16202000-3c16302000 ---p 00002000 08:02 7081092                       
/usr/lib64/libkrb5support.so.0.0
3c16302000-3c16303000 rw-p 00002000 08:02 7081092                       
/usr/lib64/libkrb5support.so.0.0
3c16400000-3c1640d000 r-xp 00000000 08:02 5701688                       
/lib64/libgcc_s-4.0.2-20051126.so.1
3c1640d000-3c1650c000 ---p 0000d000 08:02 5701688                       
/lib64/libgcc_s-4.0.2-20051126.so.1
3c1650c000-3c1650d000 rw-p 0000c000 08:02 5701688                       
/lib64/libgcc_s-4.0.2-20051126.so.1
3c16600000-3c16614000 r-xp 00000000 08:02 5701735                       
/lib64/libnsl-2.3.6.so
3c16614000-3c16713000 ---p 00014000 08:02 5701735                       
/lib64/libnsl-2.3.6.so
3c16713000-3c16714000 r--p 00013000 08:02 5701735                       
/lib64/libnsl-2.3.6.so
3c16714000-3c16715000 rw-p 00014000 08:02 5701735                       
/lib64/libnsl-2.3.6.so
3c16715000-3c16717000 rw-p 3c16715000 00:00 0 
3c16800000-3c16816000 r-xp 00000000 08:02 7087058                       
/usr/lib64/libgssapi_krb5.so.2.2
3c16816000-3c16915000 ---p 00016000 08:02 7087058                       
/usr/lib64/libgssapi_krb5.so.2.2
3c16915000-3c16917000 rw-p 00015000 08:02 7087058                       
/usr/lib64/libgssapi_krb5.so.2.2
3c16a00000-3c16ada000 r-xp 00000000 08:02 7084260                       
/usr/lib64/libstdc++.so.6.0.7
3c16ada000-3c16bda000 ---p 000da000 08:02 7084260                       
/usr/lib64/libstdc++.so.6.0.7
3c16bda000-3c16be2000 rw-p 000da000 08:02 7084260                       
/usr/lib64/libstdc++.so.6.0.7
3c16be2000-3c16bf5000 rw-p 3c16be2000 00:00 0 
3c16c00000-3c16c35000 r-xp 00000000 08:02 5701723                       
/lib64/libssl.so.0.9.7f
3c16c35000-3c16d35000 ---p 00035000 08:02 5701723                       
/lib64/libssl.so.0.9.7f
3c16d35000-3c16d3a000 rw-p 00035000 08:02 5701723                       
/lib64/libssl.so.0.9.7f
3c16d3a000-3c16d3b000 rw-p 3c16d3a000 00:00 0 
3c16e00000-3c16e70000 r-xp 00000000 08:02 7087057                       
/usr/lib64/libkrb5.so.3.2
3c16e70000-3c16f6f000 ---p 00070000 08:02 7087057                       
/usr/lib64/libkrb5.so.3.2
3c16f6f000-3c16f74000 rw-p 0006f000 08:02 7087057                       
/usr/lib64/libkrb5.so.3.2
3c17000000-3c17022000 r-xp 00000000 08:02 7087056                       
/usr/lib64/libk5crypto.so.3.0
3c17022000-3c17121000 ---p 00022000 08:02 7087056                       
/usr/lib64/libk5crypto.so.3.0
3c17121000-3c17123000 rw-p 00021000 08:02 7087056                       
/usr/lib64/libk5crypto.so.3.0
3c17200000-3c1730a000 r-xp 00000000 08:02 5701701                       
/lib64/libcrypto.so.0.9.7f
3c1730a000-3c1740a000 ---p 0010a000 08:02 5701701                       
/lib64/libcrypto.so.0.9.7f
3c1740a000-3c17428000 rw-p 0010a000 08:02 5701701                       
/lib64/libcrypto.so.0.9.7f
3c17428000-3c1742c000 rw-p 3c17428000 00:00 0 
3c17500000-3c1757f000 r-xp 00000000 08:02 7081066                       
/usr/lib64/libfreetype.so.6.3.7
3c1757f000-3c1767f000 ---p 0007f000 08:02 7081066                       
/usr/lib64/libfreetype.so.6.3.7
3c1767f000-3c1768c000 rw-p 0007f000 08:02 7081066                       
/usr/lib64/libfreetype.so.6.3.7
3c17900000-3c17921000 r-xp 00000000 08:02 7087059                       
/usr/lib64/libexpat.so.0.5.0
3c17921000-3c17a20000 ---p 00021000 08:02 7087059                       
/usr/lib64/libexpat.so.0.5.0
3c17a20000-3c17a23000 rw-p 00020000 08:02 7087059                       
/usr/lib64/libexpat.so.0.5.0
3c17b00000-3c17b26000 r-xp 00000000 08:02 7087067                       
/usr/lib64/libpng12.so.0.1.2.8
3c17b26000-3c17c26000 ---p 00026000 08:02 7087067                       
/usr/lib64/libpng12.so.0.1.2.8
3c17c26000-3c17c27000 rw-p 00026000 08:02 7087067                       
/usr/lib64/libpng12.so.0.1.2.8
2aaaaaaab000-2aaaaaaac000 rw-p 2aaaaaaab000 00:00 0 
2aaaaaab8000-2aaaaaac4000 rw-p 2aaaaaab8000 00:00 0 
2aaaaaac4000-2aaaaaacf000 r-xp 00000000 08:02 5701858                   
/lib64/libnss_files-2.3.6.so
2aaaaaacf000-2aaaaabce000 ---p 0000b000 08:02 5701858                   
/lib64/libnss_files-2.3.6.so
2aaaaabce000-2aaaaabcf000 r--p 0000a000 08:02 5701858                   
/lib64/libnss_files-2.3.6.so
2aaaaabcf000-2aaaaabd0000 rw-p 0000b000 08:02 5701858                   
/lib64/libnss_files-2.3.6.so
2aaaaac00000-2aaaaac21000 rw-p 2aaaaac00000 00:00 0 
2aaaaac21000-2aaaaad00000 ---p 2aaaaac21000 00:00 0 
7fffff96e000-7fffff982000 rwxp 7fffff96e000 00:00 0                      [stack]
7fffff982000-7fffff984000 rw-p 7fffff982000 00:00 0 
ffffffffff600000-ffffffffffe00000 ---p 00000000 00:00 0                  [vdso]
/bin/sh: line 1:  9717 Aborted                 php -f
/home/olympus/public_html/scripts/broadcast.php >/dev/null

Not very usefull! Is there any way to get it to email the php error message rather than a memory dump?

Edit: I corrected the script and im still getting these errors, so it looks like its not working. Note that the script itself is working when I run it straight from the browser.
 
Last edited:
Don't use php -f, use lynx -dump :D - more handy as you'll be running as the webserver user which, if phpsuexec isn't enabled, means there'll be no permissions conflicts (and if phpsuexec is enabled it doesn't matter either way).

As for error handling, would need to see the script for that. But mail() returns false if it hits an error so presumably that's the sort of thing you're after, so you can use a simple if():


Code:
if(!mail($foo,$bar,$lol,$zor)) { 

mail(...)

}
So in other words, if mail() fails then ask it to send an e-mail to you (you, of course, have to define what goes in the mail :)

For more advanced things you can use set_error_handler() which is quite good fun :)
 
Beansprout said:
Don't use php -f, use lynx -dump :D - more handy as you'll be running as the webserver user which, if phpsuexec isn't enabled, means there'll be no permissions conflicts (and if phpsuexec is enabled it doesn't matter either way).

As for error handling, would need to see the script for that. But mail() returns false if it hits an error so presumably that's the sort of thing you're after, so you can use a simple if():


Code:
if(!mail($foo,$bar,$lol,$zor)) { 

mail(...)

}
So in other words, if mail() fails then ask it to send an e-mail to you (you, of course, have to define what goes in the mail :)

For more advanced things you can use set_error_handler() which is quite good fun :)

Thanks Beansprout. I have just a few more questions:

1.) For a command like:

Code:
$conn = mysql_connect("localhost", "user", "pass") or die('Connection Error: ' . mysql_error());

How could I catch this and send an email with a description of the error?

2.) Is there any variable that gives you a description of the general error that last occured, that could be used in your 'mail' example to give a description of the error that occured?

Edit: what I really want is to be emailed the output of the script (but not when the output is blank), i.e. a message like the following:

Code:
Warning: mysql_connect(): Access denied for user 'user'@'localhost' (using password: YES) in /home/olympus/public_html/scripts/broadcast.php on line 7
Connection Error: Access denied for user 'user'@'localhost' (using password: YES)
 
Last edited:
Back
Top Bottom