views:

184

answers:

2

I'm looking to allow a user to enter a date and time to send out a mass email through PHP, although I'm thinking it might be best to use a *nix command to trigger the PHP process. I'm wondering if there is a way on *nix to do this without adding a cronjob to run every 15 minutes to check if there is a mass email to be sent. It's not that this is an intensive process, but it'd just be much prettier with a cronjob to add and manage. I thinking this would be somewhat similar to a Windows scheduled task that has an end date and is set to delete if it's not scheduled again.

+4  A: 

You could use at.

dragonfly
+17  A: 

You're looking for the at command.

at [options] time [date]

Execute commands at a specified time and optional date. The commands are read from standard input or from a file. (See also batch.) End input with EOF. time can be formed either as a numeric hour (with optional minutes and modifiers) or as a keyword. It can contain an optional date, formed as a month and date, a day of the week, or a special keyword (today or tomorrow). An increment can also be specified.

The at command can always be issued by a privileged user. Other users must be listed in the file /etc/at.allow if it exists; otherwise, they must not be listed in /etc/at.deny. If neither file exists, only a privileged user can issue the command.

In typical usage, you run at and input commands that you want executed at a particular time, followed by EOF.

$ at 1:00 am tomorrow at> ./total_up > output at> mail joe < output at> Entered by pressing Ctrl-D job 1 at 2003-03-19 01:00

The two commands could also be placed in a file and submitted as follows:

$ at 1:00 am tomorrow < scriptfile

Cruachan
Also make yourself familiar with the sytem and users "crontab" files.
Cheekysoft
"at" has loads of options. I find echo "<the command>" | at 2300 Does what I want 99% of the time. (any 24 hr time will do of course!)
Chris Huang-Leaver