Not strong in this thread. I want to write a bash script for VPS (on CentOS), which by crown will cycle through the dump files in the folder and import them into the database, after importing the file, you need to delete it ...

That's what I do, but the nonsense comes out:

#!/bin/bash mysql use db_cars cd / cd /home/admin/web/site/public_html/update/db/dump find -type f -iname "*.sql" | while read FILENAME; do source $FILENAME done 
  • one
    Maybe it will be easier to first go to the directory, and then do the import? And not through source , but through mysql -uUSER -pPASSWORD DB_NAME < data.sql - BOPOH

1 answer 1

You are confusing the command shell of a mysql client and bash. You can not write at the same time for one and for another. Here’s how the bash script should look like:

 #!/bin/bash cd /home/admin/web/site/public_html/update/db/dump find -type f -iname "*.sql" | while read FILENAME; do mysql -uUSER -pPASSWORD db_cars < "$FILENAME" && rm -f "$FILENAME" done