autocron.php in OSTicket - mysql

Linux Cron Job or MySQL Events doesn't work with my server, So I'm planning to use the Autocron.php in OSTicket.
My requirement is simple I need to call a Stored Procedure, 1st of every month. Everything else the procedure will take care.
Any ways on how to do it without using Linux Cron Job & Mysql Events ?

Related

Stopping a stored procedures in MySQL?

it is possible to stop a stored procedures in MySQL? Put a procedures to feed a database table for load testing with 10 million records , but the insertion is too slow and want to stop the same without having to stop the server ( there are other applications running on it ) .
try to establish a new connection to the database. If you have made the call via PHPMyAdmin procedures will need to use another browser, or close the current completely before trying to enter the database again because the server recognizes that you are still "waiting" to receive the answer to your request.
Run the SHOW PROCESSLIST command to see the process. find your Stored procedures that running and use KILL command. Example:
    
SHOW PROCESSLIST; - Will list various processes, see your procedures
    
 KILL 749; - Instead of the 749 set the process ID.

Execute script when date matches mysql cell

I have a debian machine with a mysql server.
On mysql I have a table that contains a number of rows with a datetime field.
How can I execute a php script when the date and time of the machine match with those specified in any mysql record?
a) Mysql triggers ?
b) Deamon that runs in background and checks time every n seconds ?
c) Cron?
Let me know!
Polling the MySQL will work but surely is not efficient, especially when there are a lot of "triggers".
So use a cronjob. Note: MySQL-Queries cannot schedule or cancel cronjobs. So the (i guess) PHP-Script updating that date field also has to schedule the cronjobs. Also, every time the column changes you will have to cancel the previously scheduled cronjob and schedule a new one.
Since you can't run shell command from within Mysql database the MySql Triggers are no good. The MySQL Scheduler is therefore useless too. So you need an external script to help.
I'd suggest to create a (php) script and add it to the crontab to run every minute. Its task would be to check for matching dates in the database and run whatever command you need.
I think that the easiest solution is to use , if possible , the at command.
Basically after inserting the data into mysql do the following:
1)Create (using PHP) a BASH script that runs the php file
script_1.sh should look like this:
!#/bin/bash
php /path/to/file.php
and make it executable with :
exec("chmod +x script_1.sh");
2)create a second BASH script that executes the first at the desired time:
script_2.sh should look like this:
!#/bin/bash
at H:M Y:M:D < script_1.sh
Make script_2 executable and run it with the exec command.

how to fire a Mysql trigger on an specific date and time

I have to call a store procedure at the end of each month, i just need to know how to fire a trigger on an specific date and time to call my stored procedure.
Thanks for your time.
MySQL can't do this. Instead, you should use a cronjob. If you're on a Linux system, you can create a script or program that runs your stored procedure and schedule it for execution using the crontab command.
In the command line, writing crontab -e will allow you to edit your cronjobs. In here, you can add
0 5 L * ? * /path/to/script.pl
This will run /path/to/script.pl at 5 AM, the last day of every month.
MySQL triggers are responses to query events - the clock ticking is not one of them. If you need to execute something at a specific date/time, use an external job scheduler (e.g. cron) to trigger the job.
As stated in the MySQL docs:
MySQL triggers are activated by SQL statements only.
What you can do is to create an event.
CREATE EVENT event_name
ON SCHEDULE
period_of_time
DO
your_code_here

Automation on SQL (MySQL)

I would like to ask a question for connoisseurs of SQL (MySQL, to be specific).
I have a table reservation schedules. And when a customer makes a reservation there is a time to let the client to use my service. Therefore, the reservation that he did have to leave the table reservations.
Once the time limit of use is reached, there is some method (trigger,
I believe), which automatically erase the record of this book on the
table?
If so, can someone give me some idea of ​​how to start my search for it, or it is also totally welcome some help as some more advanced lines of code.
There is also the possibility that this only be possible to be implemented via Server-Side (PHP, ASP ...), which does not believe is so true because SQL is a language very complete (to my knowledge).
Edit1: The problem is that I believe this is a task of the DBMS, so I wanted to leave this responsibility to the MySQL The problem is: how?
A trigger is triggered by either before or after an insert , update or delete event (at least in MySQL according to the docs)
What you want is some sort of scheduled job either through your application be it php, asp.net, etc.. or cron job that calls some sort of SQL script.
So to answer, it can't be done purely with triggers.
You can use SQL jobs, but if the removal logic is to complex to manage it with queries I suggest you to use a PHP script that does all that work for you.
Just write down the data check/remove logic in PHP and set up a simple cron operation for it.
The advantage of this solution is that you can access to your scripts/classes/db providers and save your time and your can log all the operations separately (instead of logging to MySQL logs, no matter what script language you are relying on).
If you have a full control of your server the scheduled operation will look like this (if you want to check your DB entries every day at 00:01):
cat /etc/cron.d/php5
0 1 * * * php /path/to/your/script.php >> /path/to/your_script.log
..otherwise you will have to check the control panel of your hosting account and figure out how to manage
You can create one more column in your table where you will create the expiration date. Then you can on your sql server create the job that will erase all records that have expiration date less than curent date.
CREATE EVENT db_name
ON SCHEDULE EVERY 10 SECOND
DO
DELETE FROM myschema.mytable WHERE expiration_date < NOW()
I hope that will help.

MySQL daily check and update

Is possible to create a routine or procedure that can automatic everyday check a date in a table.
To be simpler : I want to check if the date on a user have permitions to enter a site and when the date pass want to make the user field activated false.
routine daily
check if (todaydate < dateclient) then
client.activated= false
Thanks for all the help.
Yes, this should be a simple UPDATE query. Something like the following:
UPDATE Client
SET Activated = 'false'
WHERE NOW() < dateclient
You would obviously need to modify this for your schema and then schedule it to run daily using cron or an alternative scheduler of your choice.
Creating the routine is simple enough, but to run it on a daily basis you'll need to wrap it in a cronjob (*nix) or Scheduled Task (Windows). The routine, unfortunately, cannot execute itself - and to the best of my knowledge MySQL server does not possess the ability to run routines at scheduled intervals.