wtshing
Posts: 8
Joined: Wed Jan 31, 2018 3:52 pm

Is it possible to use cron to handle other cron

Mon Apr 09, 2018 8:39 pm

Hi guys,

I create a table to store cron data in mysql, is it possible to set a cron to check the change of the table?
As I want to use a cron to update another cron file so that it can modify and run the scheduled tasks based on the records inside the table.

Thanks.

User avatar
aTao
Posts: 1094
Joined: Wed Dec 12, 2012 10:41 am
Location: Howlin Eigg

Re: Is it possible to use cron to handle other cron

Mon Apr 09, 2018 9:04 pm

Sounds all a bit confoozled, and therefore prone to you not knowing why it has gone off and sat in a corner.
are you sure that you couldnt write a single cron job that reads the table and acts accordingly (as in do the job you were going to get the second cron to do)?
>)))'><'(((<

asandford
Posts: 1998
Joined: Mon Dec 31, 2012 12:54 pm
Location: Waterlooville

Re: Is it possible to use cron to handle other cron

Mon Apr 09, 2018 11:41 pm

wtshing wrote:
Mon Apr 09, 2018 8:39 pm
Hi guys,

I create a table to store cron data in mysql, is it possible to set a cron to check the change of the table?
As I want to use a cron to update another cron file so that it can modify and run the scheduled tasks based on the records inside the table.

Thanks.
Use triggers.

wtshing
Posts: 8
Joined: Wed Jan 31, 2018 3:52 pm

Re: Is it possible to use cron to handle other cron

Tue Apr 10, 2018 1:10 pm

aTao wrote:
Mon Apr 09, 2018 9:04 pm
Sounds all a bit confoozled, and therefore prone to you not knowing why it has gone off and sat in a corner.
are you sure that you couldnt write a single cron job that reads the table and acts accordingly (as in do the job you were going to get the second cron to do)?
How can I read the data from the mysql server located in another vm. I searched that mysql may not be able to provide this function. Any ideas?

User avatar
richlion2
Posts: 98
Joined: Thu Mar 29, 2018 7:14 am

Re: Is it possible to use cron to handle other cron

Wed Apr 11, 2018 9:22 pm

wtshing wrote:
Mon Apr 09, 2018 8:39 pm
Hi guys,

I create a table to store cron data in mysql, is it possible to set a cron to check the change of the table?
As I want to use a cron to update another cron file so that it can modify and run the scheduled tasks based on the records inside the table.

Thanks.
I haven't got my RPI at hand, you can generate the cron tab file and then overwrite it where it is normally stored using "sudo cp .... "
Theoretically you can do, but it's not an elegant way of doing it. Cron files are stored in /var/spool/cron/crontabs (each Linux user will have his own file) on Debian. They are text files, however you should use "crontab" to amend it, not VI or CP.

Normally you can list your cronjobs:
crontab -l > cron.file.txt

Edit it and then you do :
crontab < cron.file.txt

So you would have to run a script executed from another cron job that would do the latter.

If you have the job details stored in your database somehow (you didn't give the structure here...) then you can just build an SQL to generate the cron.file.txt. You also have to bare in mind you can have only one crontab file per user/ UNIX account. To run a cron job that overwrites itself, could corrupt the cron file.
“It’s nice to be important, but it’s more important to be nice.” ;)

asandford
Posts: 1998
Joined: Mon Dec 31, 2012 12:54 pm
Location: Waterlooville

Re: Is it possible to use cron to handle other cron

Wed Apr 11, 2018 10:51 pm

wtshing wrote:
Tue Apr 10, 2018 1:10 pm

How can I read the data from the mysql server located in another vm. I searched that mysql may not be able to provide this function. Any ideas?
Use database triggers, they do exactly what you want. The database will automatically execute code when tables are updated.
A database trigger is procedural code that is automatically executed in response to certain events on a particular table or view in a database. The trigger is mostly used for maintaining the integrity of the information on the database. For example, when a new record (representing a new worker) is added to the employees table, new records should also be created in the tables of the taxes, vacations and salaries. Triggers can also be used to log historical data, for example to keep track of employees' previous salaries.
For MySQL:
The MySQL trigger is a database object that is associated with a table. It will be activated when a defined action is executed for the table. The trigger can be executed when you run one of the following MySQL statements on the table: INSERT, UPDATE and DELETE and it can be invoked before or after the event.

User avatar
richlion2
Posts: 98
Joined: Thu Mar 29, 2018 7:14 am

Re: Is it possible to use cron to handle other cron

Thu Apr 12, 2018 12:09 pm

asandford wrote:
Wed Apr 11, 2018 10:51 pm
wtshing wrote:
Tue Apr 10, 2018 1:10 pm

How can I read the data from the mysql server located in another vm. I searched that mysql may not be able to provide this function. Any ideas?
Use database triggers, they do exactly what you want. The database will automatically execute code when tables are updated.
A database trigger is procedural code that is automatically executed in response to certain events on a particular table or view in a database. The trigger is mostly used for maintaining the integrity of the information on the database. For example, when a new record (representing a new worker) is added to the employees table, new records should also be created in the tables of the taxes, vacations and salaries. Triggers can also be used to log historical data, for example to keep track of employees' previous salaries.
For MySQL:
The MySQL trigger is a database object that is associated with a table. It will be activated when a defined action is executed for the table. The trigger can be executed when you run one of the following MySQL statements on the table: INSERT, UPDATE and DELETE and it can be invoked before or after the event.
I don't know anything about MySQL, but is there any scheduler in that kind of database? Normally you get those in MS-SQL and Oracle.
“It’s nice to be important, but it’s more important to be nice.” ;)

asandford
Posts: 1998
Joined: Mon Dec 31, 2012 12:54 pm
Location: Waterlooville

Re: Is it possible to use cron to handle other cron

Thu Apr 12, 2018 10:42 pm

richlion2 wrote:
Thu Apr 12, 2018 12:09 pm

I don't know anything about MySQL, but is there any scheduler in that kind of database? Normally you get those in MS-SQL and Oracle.
I'm sure further research on your part will answer that question.

Return to “General discussion”