Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

SOLVED Cron job to test file time and send email?

Discussion in 'General Discussion' started by ATom1, May 21, 2018.

Tags:
  1. ATom1

    ATom1 Registered

    Joined:
    May 21, 2018
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Utah
    cPanel Access Level:
    Website Owner
    My home network uploads a file with the date and time, which happens every five minutes. I wish to create a cron job which checks this file and sends me an email if the file is not updating. This would be an indication that my home network has lost internet connectivity.

    I have been using cPanel for years, and create my own content. Just haven't used cron jobs at all.

    Thanks for any assistance.
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    43,672
    Likes Received:
    1,788
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. ATom1

    ATom1 Registered

    Joined:
    May 21, 2018
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Utah
    cPanel Access Level:
    Website Owner
    I have created a cron job as follows:
    Code:
    /usr/bin/php -q /home2/myusrname/public_html/CheckHome.php >/dev/null
    Here is the CheckHome.php file contents:
    Code:
    <?php
    // the message
    $msg = "Internet down";
    
    $filename = 'clientFTP/marquee.txt';
    $t = time();
    $ft = (filemtime($filename));
    $td = (($t - $ft)/60);
    if ((file_exists($filename)) and $td > 5) {
       mail("1234567890@txt.att.net","Alert",$msg);
    }
    ?>
    
    I tested the php script independently, so I know it works. However, I am not getting a text when the file is not being updated. The file is normally updated once per minute.
     
  4. ATom1

    ATom1 Registered

    Joined:
    May 21, 2018
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Utah
    cPanel Access Level:
    Website Owner
    It is working now; seems like it took a while for the cron job to commence.
     
  5. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    43,672
    Likes Received:
    1,788
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    I'm glad to see it's working well. I've marked this thread as solved.

    Thanks!
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice