/    Sign up×
Community /Pin to ProfileBookmark

Dynamic Cron Jobs

Hey,
I’m new to the idea of cron jobs. But I’ve run across a situation in which I might want to use them. I’m trying to set up an admin section for when I get a new client, I can set up a newsletter mailer. Now, from what I’ve read, I can set up a cron job to send out a mailer every day at 7am, for instance. Since I’m not the sys-admin, I have to use crontab -e to do this. But with this admin, I’d like to have, in essence, the apache user, set this up with a php script. Is there any way I can do this?

Jaelan

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@NutterMar 03.2005 — You can set the cron job to run any script you want. I use PHP because that's what I know, but bash scripts work as well. You put whatever logic you want into the script.

crontab -e just edits the crontab of whoever is logged in. As admin, you'd run the same command.

I don't know if that answers your question, but I hope it at least helps.
Copy linkTweet thisAlerts:
@JaelanauthorMar 03.2005 — Yeah, but I assume you're talking about running crontab -e from a terminal. In simplest terms, what I want to know is if there is a way to run crontab -e from a .php file, and not the terminal?

Jaelan
Copy linkTweet thisAlerts:
@NutterMar 03.2005 — Why would you need to run crontab from a script? Are you talking about entering entries into the cron job list from PHP? If so, I would suggest a PHP script that you can edit that's called from cron.

I don't know of a way to directly edit the cron jobs from PHP, but I think they're stored as a text file somewhere. But, there are warnings all over the place about directly editing the crontab file instead of using crontab -e.
Copy linkTweet thisAlerts:
@NogDogMar 03.2005 — If I'm understanding your needs correctly, I would suggest creating a crontab file (via crontab -e) using your normal user account. Just give it one line calling a script file in your user's directory tree. Give that script the necessary permissions so that it can be written to by your PHP scripts, then have your PHP scripts modify that script, not try to modify the crontab file itself. Then the only time you would need to edit your crontab file is if you want to change the periodicity - all the details concerning what actually happens when the cron job fires off would be controlled in the script called by cron.
Copy linkTweet thisAlerts:
@handong888Mar 03.2005 — what is the cron mean?
Copy linkTweet thisAlerts:
@NogDogMar 03.2005 — "cron" is a daemon program run on UNIX/Linux systems used to call other programs on a regular schedule, somewhat analogous to the Windows Scheduler program. "crontab" is the program used to view/edit the files that cron reads to fire off these scheduled events.
×

Success!

Help @Jaelan spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...