Re: From bash script (Debian Bookworm) login and query to MariaDB

"J.O. Aho" <[email protected]> Thu, 2 Nov 2023 12:22:01 +0100
Newsgroups comp.databases.mysql
Message-ID <[email protected]>
On 02/11/2023 11.46, ^Bart wrote:
>> Thanks for your reply, I used PHP years and years ago and I don't 
>> remember it very well but really thanks to share this solution! :)
> 
> I did in my crontab this:
> 
> */5 * * * * /usr/bin/mysql -u my_username -h localhost -p my_password < 
> /home/itoffice/query.sql


this in /etc/crontab or did you use it as your personal crontab with 
"crontab -e"?

if the later, then your user need to have the right to read the file and 
of course have the right to access the content in the itoffice directory.

if /etc/crontab then add who is executing the command and it can be good 
to put parentheses around command too

*/5 * * * * (root) (/usr/bin/mysql -umy_username -pmy_password 
databasename <
  /home/itoffice/query.sql)



> I think I must use php like what this site said: 
> https://stackoverflow.com/questions/9948220/how-can-i-set-a-crontab-to-execute-a-mysql-query-and-log-the-output

No you don't, it's just what he did.


> I think also I should save php file not in my home folder like 
> /home/itoffice but in /var/www/html right?

That is much about how you use the php script, if you use it like a bash 
script then no you don't put it there. If it's part of your web site, 
then yes.

Php can be used for websites, scripting and even create gui 
applications, it may not be the best option in all situations.

-- 
  //Aho