0

I need to run a bash script after insert row in mariadb database.

This is my script :

mysql {database} -u{user} -p{passwd} < req_mp3.sql #Create csv of my table
liste_requete=$(ls /tmp | grep csv)
for i in ${liste_requete[@]}; do              
            line=$(cat /tmp/${i})

            for b in ${line[@]}; do


              mp3=$(echo ${b}| awk -F"|" '{print $1}')
              id=$(echo ${b} | awk -F"|" '{print $3}')
              time=$(ffmpeg -i /tracks/${mp3} 2>&1 | grep Duration | awk '{print $2}' | tr -d ,i | awk -F"00:" '{print $2}'| awk -F"." '{print $1}')



                printf " UPDATE tbl_mp3 SET mp3_url = '${mp3}', mp3_duration = '${time}', cat_id = '${tag}' , status= '1' WHERE id='${id}'; \n" >> update.sql

            done
done

mysql {database} -u{user} -p{passwd} < update.sql

I tired this :

 DELIMITER ;;
    CREATE TRIGGER `tbl_mp3_ai` AFTER INSERT ON `tbl_mp3` FOR EACH ROW
    BEGIN

    system /imports/fnish.sh

    END;;
    DELIMITER ;

But not work

Can you help me ?

thx :)

lejuste
  • 1
  • 1
  • Can you indicate what the help is you need? What doesn't work? – M. le Rutte Apr 14 '18 at 10:38
  • `mysql {database} -u{user} -p{passwd} < req_mp3.sql #Create csv of my table` doesn't like it that that is creating a CVS that's importing a sql file.. if you wan't to make exports you need to use mysqldump program or something more like `mysql {database} -u{user} -p{passwd} -e 'SELECT ... INTO ....' read -> https://dev.mysql.com/doc/refman/5.7/en/select-into.html` – Raymond Nijland Apr 14 '18 at 10:50
  • The script works fine , but i need to run script automatically when new entry is insert into my table in my database . thanks for mysql ... -e ;) – lejuste Apr 14 '18 at 11:03
  • @RaymondNijland Not necessarily. MySQL Server *itself* provides commands to export tables to the file system, i.e. you can log into MySQL, for example using `mysqlclient`, and then let it export tables or records. I assume that the OP's `req_mp3.sql` does exactly this. – Binarus Apr 14 '18 at 12:52
  • @Binarus , the req_mp3.sql contains : SELECT mp3_url,mp3_duration,id FROM tbl_mp3 WHERE tag LIKE '%frenchcore,%' AND status = 0 INTO OUTFILE '/tmp/frenchcore.csv' CHARACTER SET utf8 FIELDS TERMINATED BY '|' ESCAPED BY '\\' LINES TERMINATED BY '\n' ; – lejuste Apr 14 '18 at 13:25

0 Answers0