OOC
OOC

Reputation: 1

How to structure a cron job and script to execute sql command

I have a MySQL database accessible through CPANEL. I want to execute a SQL command to DELETE from dbtable where eventdate = 'YYYY-MM-DD'. This is my cron job.

curl -L --max-redirs 1000 -v "https://ottawaoc.ca/test/files/delete_dates.sh" 1>/dev/null   

and here is the shell script

#!/bin/bash
mysql --user = "ottawaoc_test" --password = "test ps" --database = "ottawaoc_test" --execute ="DELETE FROM `h8be5_eventregistration` WHERE `eventdate` = '2020-09-27'"

(I do insert the correct password.) I get output mailed to me and it seems to get the shell script but nothing happens within the database.

Could someone help to give me the correct commands and/or tell me how I can get errors from MySQL.

Upvotes: 0

Views: 1121

Answers (1)

fadil eldin
fadil eldin

Reputation: 143

I used to run mysql crons by putting this in the shell:

#!/bin/bash
echo "mysql statement;" | mysql -B -hHOST -uUSER -pPASS DBNAME

Upvotes: 1

Related Questions