Community Forums
Connect with us on LinkedIn
Community Notice
+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 15 of 17
  1. #1
    Member cpane1's Avatar
    Join Date
    Jun 2007
    Posts
    54

    Default what is /dev/null 2>&1 ?

    Hi,

    I have a problem where I have set up a cron to mail me when my mysql is down...
    I now receive emails every 20 minutes but the problem is that it mails me blank emails, that means even if the mysql is not down I receice BLANK emails. What cron should I set up so that I will receive emails only if mysql is down ??
    my cron:

    */20 * * * * /usr/bin/php /home/username/public_html/admin/mysqlstat.php

    Also as my subject line suggests what is what is /dev/null 2>&1 ? does that relates to my query above ??? Please help...
    Regards,
    cPane1®

  2. #2
    Member darren.nolan's Avatar
    Join Date
    Oct 2007
    Posts
    259

    Default

    I believe cPanel will send you an email every 5 minutes if one of your monitored services is down - Under WHM -> Service Manager -> Ensure the box to monitor MySQL is selected.

    With your cron - change it to;

    */20 * * * * /usr/bin/php -q /home/username/public_html/admin/mysqlstat.php

    -q is quiet or not header mode (might explain why you are getting blank emails?) - and have your mysqlstat.php file generate an email if the service is down.

    From LinuxHelp.net http://www.linuxhelp.net/guides/cron/
    >> /dev/null 2>&1 part means to send any standard output to /dev/null (the linux trash can) and to redirect standard error (2) to the same place as the standard output (1). Basically it runs the command without any output to a terminal etc.

    Hope this helps

  3. #3
    Member cpane1's Avatar
    Join Date
    Jun 2007
    Posts
    54

    Default

    Quote Originally Posted by darren.nolan View Post
    I believe cPanel will send you an email every 5 minutes if one of your monitored services is down - Under WHM -> Service Manager -> Ensure the box to monitor MySQL is selected.

    With your cron - change it to;

    */20 * * * * /usr/bin/php -q /home/username/public_html/admin/mysqlstat.php

    -q is quiet or not header mode (might explain why you are getting blank emails?) - and have your mysqlstat.php file generate an email if the service is down.

    From LinuxHelp.net http://www.linuxhelp.net/guides/cron/
    >> /dev/null 2>&1 part means to send any standard output to /dev/null (the linux trash can) and to redirect standard error (2) to the same place as the standard output (1). Basically it runs the command without any output to a terminal etc.

    Hope this helps
    Hiya,

    Thanks for your response on this, but I am using this cron for a client ..hosted on the server.

    I simply want to make the cron email him only if there is a failure or errors with mysql server... I do not want the BLANK emails every 20 minutes...

    Please help....
    Regards,
    cPane1®

  4. #4
    Member
    Join Date
    Nov 2007
    Posts
    20

    Lightbulb

    Hi,

    no worries,
    You can set it up directly in crontab file. Open your crontab file and assign the cron mail address for him .
    The format looks like..
    -----------------
    ]crontab -e <username>
    MAILTO=username@domain.com
    */20 * * * * /usr/bin/php -q /home/username/public_html/admin/mysqlstat.php
    ----------------


    Thanks
    Last edited by rbalaji; 11-30-2007 at 02:50 PM.

  5. #5
    Member cpane1's Avatar
    Join Date
    Jun 2007
    Posts
    54

    Default

    Quote Originally Posted by rbalaji View Post
    Hi,

    no worries,
    You can set it up directly in crontab file. Open your crontab file and assign the cron mail address for him .
    The format looks like..
    -----------------
    ]crontab -e <username>
    MAILTO=username@domain.com
    */20 * * * * /usr/bin/php -q /home/username/public_html/admin/mysqlstat.php
    ----------------


    Thanks
    Hi rbalaji,

    Thanks, but I have already set that up and I am receiving this BLANK emails even if mysql is not down or have any errors with it.........

    One thing to note that the cron does send emails when there is a mysql failure...

    so in short here how it goes.

    cron emails when....

    there is a failure with mysql
    there is no mysql failure....BLANK email <---

    I do not want cron to email me when is no mysql failure.......



    Hope I am clear this time....

    Please help..
    Regards,
    cPane1®

  6. #6
    Member darren.nolan's Avatar
    Join Date
    Oct 2007
    Posts
    259

    Default

    I stress the -q after /php

  7. #7
    Member cpane1's Avatar
    Join Date
    Jun 2007
    Posts
    54

    Default

    Quote Originally Posted by darren.nolan View Post
    I stress the -q after /php
    I tried the above to no avail...Still receiving the blank emails....

    please help....

    I don't think this works with cron..... is it ?
    Regards,
    cPane1®

  8. #8
    Member darren.nolan's Avatar
    Join Date
    Oct 2007
    Posts
    259

    Default

    What is your PHP script?

  9. #9
    Member cpane1's Avatar
    Join Date
    Jun 2007
    Posts
    54

    Default

    Quote Originally Posted by darren.nolan View Post
    What is your PHP script?
    Hi,

    attached is the script......

    It used to work but now suddenly its not.....

    cron set as:

    */20 * * * * /usr/bin/php -q /home/username/public_html/admin/mysqlstat.php

    Any other alternative besides php -q ? like wget, get .....
    Attached Files
    Regards,
    cPane1®

  10. #10
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    10,718
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    Quote Originally Posted by cpane1 View Post
    ...

    Any other alternative besides php -q ? like wget, get .....
    One method I used for a long time was placing the script in public_html (like Drupal does with its cron script) then call lynx to request that "page".

    Another alternative is to make your PHP script a PHP shell script. That'd mean placing a hashbang at the top of the file as you would with a Perl script, except calling the PHP binary instead. If you don't want to echo output, use the -q parameter in there as well.

    In my own scripts though, when I want an email about something, I put in my own calls to mail() rather than relying on some implicit functionality of cron.

  11. #11
    Member cpane1's Avatar
    Join Date
    Jun 2007
    Posts
    54

    Default

    Quote Originally Posted by cPanelDavidG View Post
    In my own scripts though, when I want an email about something, I put in my own calls to mail() rather than relying on some implicit functionality of cron.
    Can you please let me know any such call (using mail() function) that can be added into the script that I have provided.....


    That would be much appreciated....

    Regards,
    cPane1®

  12. #12
    Member brianoz's Avatar
    Join Date
    Mar 2004
    Location
    Melbourne, Australia
    Posts
    1,093
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    Google is your friend or php.net/mail, or phpfreaks, or sitepoint ...

  13. #13
    Member darren.nolan's Avatar
    Join Date
    Oct 2007
    Posts
    259

    Default

    Quote Originally Posted by brianoz View Post
    Google is your friend or php.net/mail, or phpfreaks, or sitepoint ...
    mmm -sitepoint.

  14. #14
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    10,718
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    php.net/insert function name here is definitely a useful resource for PHP scripting, especially the user-contributed comments.
    Last edited by cPanelDavidG; 12-05-2007 at 10:14 AM. Reason: Combatting auto-linking

  15. #15
    Member cpane1's Avatar
    Join Date
    Jun 2007
    Posts
    54

    Default

    Quote Originally Posted by cPanelDavidG View Post
    php.net/insert function name here is definitely a useful resource for PHP scripting, especially the user-contributed comments.

    Thanks for all your help...... but all seems to be in vain as the client want that script and no other way round.. he says it USED to WORK.. and now its not....
    I don't understand whats changed on the server ......

    also does cron really does what the client really looking for ??? this is a BIG question.....

    guys..come one help me in this......


    Regards,
    cPane1®

Similar Threads & Tags
Similar threads

  1. cron output sends emails even with /dev/null 2>&1
    By Valuehosted in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 04-17-2010, 08:08 AM
  2. some mail /dev/null some mail not /dev/null....
    By bignose in forum cPanel and WHM Discussions
    Replies: 0
    Last Post: 01-15-2010, 09:37 AM
  3. Is there a way to set /dev/null to :fail:?
    By jackie46 in forum cPanel and WHM Discussions
    Replies: 3
    Last Post: 04-29-2006, 10:57 AM
  4. /dev/null does not exist
    By Secret Agent in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 07-07-2005, 06:50 PM
  5. Logging to /dev/null
    By keyDet79 in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 10-05-2003, 08:26 AM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube