Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run a script on a specific date?

Tags:

linux

php

I want to run a php script on christmas that will email my family and friends merry christmas while I am out of town and un-able to contact them.

The way I just set it up was I have a cron run the script every day, and then the script checks to see if the date is Dec 25th. If it is then the script sends the emails out.

Is there a more elegant way to do this. Or a way to have linux just send run the script on the 25th rather than checking everyday. I know it's not that big of a deal, but still just for the sake of knowing.

like image 443
austinbv Avatar asked Apr 08 '26 02:04

austinbv


2 Answers

You can fire cron on a particular date only, if you like. This'll fire at 8 AM on Christmas.

0 8 25 12 * /path/to/script
like image 169
ceejayoz Avatar answered Apr 09 '26 14:04

ceejayoz


This day will echo happy Xmas on Xmas day (the 25th)

<?php

date_default_timezone_set('America/Montevideo');


$exp_date = "2010-12-25";
$todays_date = date("Y-m-d");

$today = strtotime($todays_date);
$expiration_date = strtotime($exp_date);

if ($expiration_date == $today) {

echo "happy christmas"; #you can put your Xmas script here

} else {

echo "not every day can bechristmas";

}

?>

Is this what you were looking for?

BTW:

Yot Xmas eail can be send with mail() with PHP, something like:

$to      = '[email protected]';
$subject = 'Merry Xmas';
$message = 'Merry Xmas and a happy new year';
$headers = 'From: [email protected]' . "\r\n" .
    'Reply-To: [email protected]' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
like image 34
Trufa Avatar answered Apr 09 '26 15:04

Trufa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!