Skip to content

Instantly share code, notes, and snippets.

@kuntalchandra
Created September 11, 2017 12:42
Show Gist options
  • Save kuntalchandra/ac8f1f04b708a2c9951ef1b1fedc7fee to your computer and use it in GitHub Desktop.
Save kuntalchandra/ac8f1f04b708a2c9951ef1b1fedc7fee to your computer and use it in GitHub Desktop.
Basic program to send desktop notifications in Ubuntu
#!/bin/bash
COUNT=`php /etc/checkDuePremium.php`
if [ $COUNT -gt 0 ]
then
notify-send 'Hello Kuntal!' "$COUNT premium is due. Check your inbox for details" --icon=dialog-information
echo insurance reminder job ran at `date` >> /var/log/custom.log
fi
<?php
//basic example to send email using sSMTP and respond to a bash script
$set = [
'Test' => [8 => [4000, 5000]],
'Test1' => [3 => [1234], 12 => [5678, 9012]],
'Test2' => [9 => [1000, 2000]],
];
$month = date('n');
$to = '[email protected]';
$premiumCount = 0;
$totalPremium = 0;
foreach ($set as $type => $values) {
$subject = 'Premium is due: ';
$months = array_keys($values);
if (in_array($month, $months)) {
$sum = array_sum($values[$month]);
$totalPremium += $sum;
$premiumCount = count($values[$month]);
$subject .= $type;
$message = "There are " . $premiumCount . " due premium(s)\n of total Rs. $sum";
mail($to, $subject, $message);
}
}
echo $premiumCount;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment