Source multiple sql files with blank in name

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I'm actually blocking on a stupid thing ... yet i can't get it throught.



We've got a git repository on which we have our php files and our sql patch.
Every time i update my repo, i have to check if any sql patch has to be played.
To avoid searching wich one is to play, i've made a small script that give me every sql file taht my last git pull gave me:



find $MY_DIR/scripts/sandbox/migrations -type f -newermt $(date +'%Y-%m-%d') ! -newermt $(date +'%Y-%m-%d' --date="tomorrow") -not -path "$MY_DIR/scripts/sandbox/migrations/generated/*"


This gives me and output that looks like this



/home/carpette/www/myFolder/scripts/sandbox/migrations/done/2017.12.14 - script1.sql
/home/carpette/www/myFolder/scripts/sandbox/migrations/done/2017.09.28 - script2.sql
/home/carpette/www/myFolder/scripts/sandbox/migrations/done/2017.12.15 - script3.sql
/home/carpette/www/myFolder/scripts/sandbox/migrations/done/2017.12.12 - script4.sql


Now, i'm trying to source those files automaticaly in mysql.
I've tried doing something like this:



mysql myDataBase < $(./myStript.sh)



But i get an error message with ambiguous redirection.



So i tried:



cat $(./myScript.sh) | mysql myDataBase



But now, the space contained in my filename path is blocking, and mysql said "no existing file" because it takes only /home/carpette/www/myFolder/scripts/sandbox/migrations/done/2017.09.28 as filename path.



I guess i have to escape the blanks, but i'm not finding any elegant solution that works.



Update: I want to keep myScript.sh independant, so that i can steel use it in other things.







share|improve this question






















  • I think you would be better off executing the myStript.sh script and then take each line as a file path and pass it to mysql with "mysql myDataBase < $RETURNEDLINE"
    – Raman Sailopal
    Jan 5 at 14:38










  • In fact, that is litteraly what i'm trying to do...
    – Carpette
    Jan 5 at 14:41














up vote
0
down vote

favorite












I'm actually blocking on a stupid thing ... yet i can't get it throught.



We've got a git repository on which we have our php files and our sql patch.
Every time i update my repo, i have to check if any sql patch has to be played.
To avoid searching wich one is to play, i've made a small script that give me every sql file taht my last git pull gave me:



find $MY_DIR/scripts/sandbox/migrations -type f -newermt $(date +'%Y-%m-%d') ! -newermt $(date +'%Y-%m-%d' --date="tomorrow") -not -path "$MY_DIR/scripts/sandbox/migrations/generated/*"


This gives me and output that looks like this



/home/carpette/www/myFolder/scripts/sandbox/migrations/done/2017.12.14 - script1.sql
/home/carpette/www/myFolder/scripts/sandbox/migrations/done/2017.09.28 - script2.sql
/home/carpette/www/myFolder/scripts/sandbox/migrations/done/2017.12.15 - script3.sql
/home/carpette/www/myFolder/scripts/sandbox/migrations/done/2017.12.12 - script4.sql


Now, i'm trying to source those files automaticaly in mysql.
I've tried doing something like this:



mysql myDataBase < $(./myStript.sh)



But i get an error message with ambiguous redirection.



So i tried:



cat $(./myScript.sh) | mysql myDataBase



But now, the space contained in my filename path is blocking, and mysql said "no existing file" because it takes only /home/carpette/www/myFolder/scripts/sandbox/migrations/done/2017.09.28 as filename path.



I guess i have to escape the blanks, but i'm not finding any elegant solution that works.



Update: I want to keep myScript.sh independant, so that i can steel use it in other things.







share|improve this question






















  • I think you would be better off executing the myStript.sh script and then take each line as a file path and pass it to mysql with "mysql myDataBase < $RETURNEDLINE"
    – Raman Sailopal
    Jan 5 at 14:38










  • In fact, that is litteraly what i'm trying to do...
    – Carpette
    Jan 5 at 14:41












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm actually blocking on a stupid thing ... yet i can't get it throught.



We've got a git repository on which we have our php files and our sql patch.
Every time i update my repo, i have to check if any sql patch has to be played.
To avoid searching wich one is to play, i've made a small script that give me every sql file taht my last git pull gave me:



find $MY_DIR/scripts/sandbox/migrations -type f -newermt $(date +'%Y-%m-%d') ! -newermt $(date +'%Y-%m-%d' --date="tomorrow") -not -path "$MY_DIR/scripts/sandbox/migrations/generated/*"


This gives me and output that looks like this



/home/carpette/www/myFolder/scripts/sandbox/migrations/done/2017.12.14 - script1.sql
/home/carpette/www/myFolder/scripts/sandbox/migrations/done/2017.09.28 - script2.sql
/home/carpette/www/myFolder/scripts/sandbox/migrations/done/2017.12.15 - script3.sql
/home/carpette/www/myFolder/scripts/sandbox/migrations/done/2017.12.12 - script4.sql


Now, i'm trying to source those files automaticaly in mysql.
I've tried doing something like this:



mysql myDataBase < $(./myStript.sh)



But i get an error message with ambiguous redirection.



So i tried:



cat $(./myScript.sh) | mysql myDataBase



But now, the space contained in my filename path is blocking, and mysql said "no existing file" because it takes only /home/carpette/www/myFolder/scripts/sandbox/migrations/done/2017.09.28 as filename path.



I guess i have to escape the blanks, but i'm not finding any elegant solution that works.



Update: I want to keep myScript.sh independant, so that i can steel use it in other things.







share|improve this question














I'm actually blocking on a stupid thing ... yet i can't get it throught.



We've got a git repository on which we have our php files and our sql patch.
Every time i update my repo, i have to check if any sql patch has to be played.
To avoid searching wich one is to play, i've made a small script that give me every sql file taht my last git pull gave me:



find $MY_DIR/scripts/sandbox/migrations -type f -newermt $(date +'%Y-%m-%d') ! -newermt $(date +'%Y-%m-%d' --date="tomorrow") -not -path "$MY_DIR/scripts/sandbox/migrations/generated/*"


This gives me and output that looks like this



/home/carpette/www/myFolder/scripts/sandbox/migrations/done/2017.12.14 - script1.sql
/home/carpette/www/myFolder/scripts/sandbox/migrations/done/2017.09.28 - script2.sql
/home/carpette/www/myFolder/scripts/sandbox/migrations/done/2017.12.15 - script3.sql
/home/carpette/www/myFolder/scripts/sandbox/migrations/done/2017.12.12 - script4.sql


Now, i'm trying to source those files automaticaly in mysql.
I've tried doing something like this:



mysql myDataBase < $(./myStript.sh)



But i get an error message with ambiguous redirection.



So i tried:



cat $(./myScript.sh) | mysql myDataBase



But now, the space contained in my filename path is blocking, and mysql said "no existing file" because it takes only /home/carpette/www/myFolder/scripts/sandbox/migrations/done/2017.09.28 as filename path.



I guess i have to escape the blanks, but i'm not finding any elegant solution that works.



Update: I want to keep myScript.sh independant, so that i can steel use it in other things.









share|improve this question













share|improve this question




share|improve this question








edited Jan 5 at 14:54

























asked Jan 5 at 14:29









Carpette

1691212




1691212











  • I think you would be better off executing the myStript.sh script and then take each line as a file path and pass it to mysql with "mysql myDataBase < $RETURNEDLINE"
    – Raman Sailopal
    Jan 5 at 14:38










  • In fact, that is litteraly what i'm trying to do...
    – Carpette
    Jan 5 at 14:41
















  • I think you would be better off executing the myStript.sh script and then take each line as a file path and pass it to mysql with "mysql myDataBase < $RETURNEDLINE"
    – Raman Sailopal
    Jan 5 at 14:38










  • In fact, that is litteraly what i'm trying to do...
    – Carpette
    Jan 5 at 14:41















I think you would be better off executing the myStript.sh script and then take each line as a file path and pass it to mysql with "mysql myDataBase < $RETURNEDLINE"
– Raman Sailopal
Jan 5 at 14:38




I think you would be better off executing the myStript.sh script and then take each line as a file path and pass it to mysql with "mysql myDataBase < $RETURNEDLINE"
– Raman Sailopal
Jan 5 at 14:38












In fact, that is litteraly what i'm trying to do...
– Carpette
Jan 5 at 14:41




In fact, that is litteraly what i'm trying to do...
– Carpette
Jan 5 at 14:41










2 Answers
2






active

oldest

votes

















up vote
0
down vote



accepted










./myStript.sh | while read line
do
mysql myDataBase < "$line"
done


Run the script and take the output line by line, passing the result as a file path to mysql for it to read in and process. Add quotes to the $line variable (file path) to take account of spaces.






share|improve this answer



























    up vote
    0
    down vote













    Something like



    find $MY_DIR/scripts/sandbox/migrations -type f
    -newermt $(date +'%Y-%m-%d') !
    -newermt $(date +'%Y-%m-%d' --date="tomorrow")
    -not -path "$MY_DIR/scripts/sandbox/migrations/generated/*"
    -exec msqlclient MyDatabase -u $USER -h $HOST -p < "" ;



    Replace $USER and $HOST as appropriate






    share|improve this answer




















    • I might have specified that i want to keep both treatment independants. I update my question
      – Carpette
      Jan 5 at 14:53










    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );








     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f414996%2fsource-multiple-sql-files-with-blank-in-name%23new-answer', 'question_page');

    );

    Post as a guest






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    ./myStript.sh | while read line
    do
    mysql myDataBase < "$line"
    done


    Run the script and take the output line by line, passing the result as a file path to mysql for it to read in and process. Add quotes to the $line variable (file path) to take account of spaces.






    share|improve this answer
























      up vote
      0
      down vote



      accepted










      ./myStript.sh | while read line
      do
      mysql myDataBase < "$line"
      done


      Run the script and take the output line by line, passing the result as a file path to mysql for it to read in and process. Add quotes to the $line variable (file path) to take account of spaces.






      share|improve this answer






















        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        ./myStript.sh | while read line
        do
        mysql myDataBase < "$line"
        done


        Run the script and take the output line by line, passing the result as a file path to mysql for it to read in and process. Add quotes to the $line variable (file path) to take account of spaces.






        share|improve this answer












        ./myStript.sh | while read line
        do
        mysql myDataBase < "$line"
        done


        Run the script and take the output line by line, passing the result as a file path to mysql for it to read in and process. Add quotes to the $line variable (file path) to take account of spaces.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 5 at 14:47









        Raman Sailopal

        1,18117




        1,18117






















            up vote
            0
            down vote













            Something like



            find $MY_DIR/scripts/sandbox/migrations -type f
            -newermt $(date +'%Y-%m-%d') !
            -newermt $(date +'%Y-%m-%d' --date="tomorrow")
            -not -path "$MY_DIR/scripts/sandbox/migrations/generated/*"
            -exec msqlclient MyDatabase -u $USER -h $HOST -p < "" ;



            Replace $USER and $HOST as appropriate






            share|improve this answer




















            • I might have specified that i want to keep both treatment independants. I update my question
              – Carpette
              Jan 5 at 14:53














            up vote
            0
            down vote













            Something like



            find $MY_DIR/scripts/sandbox/migrations -type f
            -newermt $(date +'%Y-%m-%d') !
            -newermt $(date +'%Y-%m-%d' --date="tomorrow")
            -not -path "$MY_DIR/scripts/sandbox/migrations/generated/*"
            -exec msqlclient MyDatabase -u $USER -h $HOST -p < "" ;



            Replace $USER and $HOST as appropriate






            share|improve this answer




















            • I might have specified that i want to keep both treatment independants. I update my question
              – Carpette
              Jan 5 at 14:53












            up vote
            0
            down vote










            up vote
            0
            down vote









            Something like



            find $MY_DIR/scripts/sandbox/migrations -type f
            -newermt $(date +'%Y-%m-%d') !
            -newermt $(date +'%Y-%m-%d' --date="tomorrow")
            -not -path "$MY_DIR/scripts/sandbox/migrations/generated/*"
            -exec msqlclient MyDatabase -u $USER -h $HOST -p < "" ;



            Replace $USER and $HOST as appropriate






            share|improve this answer












            Something like



            find $MY_DIR/scripts/sandbox/migrations -type f
            -newermt $(date +'%Y-%m-%d') !
            -newermt $(date +'%Y-%m-%d' --date="tomorrow")
            -not -path "$MY_DIR/scripts/sandbox/migrations/generated/*"
            -exec msqlclient MyDatabase -u $USER -h $HOST -p < "" ;



            Replace $USER and $HOST as appropriate







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jan 5 at 14:50









            ivanivan

            3,1291213




            3,1291213











            • I might have specified that i want to keep both treatment independants. I update my question
              – Carpette
              Jan 5 at 14:53
















            • I might have specified that i want to keep both treatment independants. I update my question
              – Carpette
              Jan 5 at 14:53















            I might have specified that i want to keep both treatment independants. I update my question
            – Carpette
            Jan 5 at 14:53




            I might have specified that i want to keep both treatment independants. I update my question
            – Carpette
            Jan 5 at 14:53












             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f414996%2fsource-multiple-sql-files-with-blank-in-name%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?