GrandVizier
August 17th, 2011, 01:25 AM
I wrote myself a little script to give myself an alert when my system is running low on memory. Here is the script:
<?php
$mem_string = exec('cat /proc/meminfo | grep MemFree');
$mem_string = str_ireplace('MemFree:', '', $mem_string);
$mem_string = trim(str_ireplace('kb', '', $mem_string));
$mem_total = exec('cat /proc/meminfo | grep MemTotal');
$mem_total = str_ireplace('MemTotal:', '', $mem_total);
$mem_total = trim(str_ireplace('kb', '', $mem_total));
if($mem_total > 0){
$percentage = ($mem_string / $mem_total) * 100;
if($percentage < 10){
exec('notify-send " Memory is LOW"');
}
}else{
return;
}
?>
it works just fine when I run:
/usr/bin/php /home/jeff/memory_script.php
but when I add
22 * * * * root /usr/bin/php /home/jeff/memory_script.php
to /etc/crontab it does nothing - having a look in /var/log/syslog shows:
Aug 17 01:22:01 hardcore cron[986]: (*system*) RELOAD (/etc/crontab)
Aug 17 01:22:01 hardcore CRON[29564]: (root) CMD (/usr/bin/php /home/jeff/memory_script.php)
Aug 17 01:22:02 hardcore CRON[29563]: (CRON) info (No MTA installed, discarding output)
<?php
$mem_string = exec('cat /proc/meminfo | grep MemFree');
$mem_string = str_ireplace('MemFree:', '', $mem_string);
$mem_string = trim(str_ireplace('kb', '', $mem_string));
$mem_total = exec('cat /proc/meminfo | grep MemTotal');
$mem_total = str_ireplace('MemTotal:', '', $mem_total);
$mem_total = trim(str_ireplace('kb', '', $mem_total));
if($mem_total > 0){
$percentage = ($mem_string / $mem_total) * 100;
if($percentage < 10){
exec('notify-send " Memory is LOW"');
}
}else{
return;
}
?>
it works just fine when I run:
/usr/bin/php /home/jeff/memory_script.php
but when I add
22 * * * * root /usr/bin/php /home/jeff/memory_script.php
to /etc/crontab it does nothing - having a look in /var/log/syslog shows:
Aug 17 01:22:01 hardcore cron[986]: (*system*) RELOAD (/etc/crontab)
Aug 17 01:22:01 hardcore CRON[29564]: (root) CMD (/usr/bin/php /home/jeff/memory_script.php)
Aug 17 01:22:02 hardcore CRON[29563]: (CRON) info (No MTA installed, discarding output)