This isn't the best way to do it! This is only for my case.
I want to receive notifications if my laptop gets disconnect from the internet.
- a folder on Apache Server (w/ PHP)
- a limited user account for that server. (no root, I can only use what is installed on that machine)
-
cron
Every X minutes run "send_ping.sh" that sends a request to the server.
*/X * * * * bash <path>/send_ping.sh
-
index.php
Gives how many minutes since last ping, just for control.
<?php $FILE = file_get_contents('./<File>.txt', true); $NOW = strtotime(date("Y-m-d h:i")); $PING = strtotime($FILE); $X = round(abs($NOW - $PING) / 60,2); ?> <html> <head> <title> Ping </title> </head> <body> <h1>Last Ping: <?php echo $X ?> Minutes</h1> </body> </html>
-
ping_[random string].php
Receives requests and check if everything is ok, update the timestamp on X file.
-
check.sh
Check X file for how many minutes since the last ping, IF [ TOTAL > ex 5 minutes ] then sends a notification to my cellphone.
-
cron
Every X minutes run "check.sh"
*/X * * * * bash <path>/check_ping.sh
- get a private VPS ;) so I don't need this
- play with mobile connections