Bash loop for detecting equal folder sizes

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











up vote
-1
down vote

favorite












I would like to detect when the transfer of a large amount of files is completed. I would like to accomplish this by detecting the size of the folder with a time delay.



Below is what I have done,



 #!/bin/bash

firstSize= du -s /Users/test/Desktop/folder | cut -f1

sleep 3
newSize= du -s /Users/test/Desktop/folder | cut -f1


until [ $firstSize -eq $newSize ]
do
firstSize=$newSize
sleep 3
newSize= du -s /Users/test/Desktop/folder | cut -f1

done

echo 'Done'


The until loop is not working because even when the firstSize and the newSize are not equal the loop completes. I am not familiar with writing Bash scripts so I am just making mistakes. This loop is ported over from an applescript I had wrote for the same purpose but I need something more reliable.










share|improve this question



















  • 2




    See How can I assign the output of a command to a shell variable?
    – steeldriver
    Sep 16 at 21:35






  • 1




    Can't you measure the file size rather than the directory size? Could your sending process send the file with a temporary suffix (eg .tmp) and then rename it on successful transfer? (Does OSX have inotify? If so that can provide a far more efficient way of determining that a file has landed.)
    – roaima
    Sep 16 at 21:37










  • Hi @lightwalker. Would you please add more clarifications about what you would like to achieve, so we can help you more efficiently!! How do you transfer your files between folders? do you use rsync, scp, ... ect ? What is the source folder and what is the target folder? Do you want to detect the equality between the source and target folders? let's say that you are using rsync to transfer files between folder A to folder B, let's say the the folders sizes A=B what next? what is the purpose of the script?
    – Goro
    Sep 16 at 21:57










  • Thanks @steeldriver that link helped and it is now working.
    – lightwalker
    Sep 16 at 22:34










  • @roaima thanks, the reason for the folder rather than the file is I have do not have control over the file.
    – lightwalker
    Sep 16 at 22:35














up vote
-1
down vote

favorite












I would like to detect when the transfer of a large amount of files is completed. I would like to accomplish this by detecting the size of the folder with a time delay.



Below is what I have done,



 #!/bin/bash

firstSize= du -s /Users/test/Desktop/folder | cut -f1

sleep 3
newSize= du -s /Users/test/Desktop/folder | cut -f1


until [ $firstSize -eq $newSize ]
do
firstSize=$newSize
sleep 3
newSize= du -s /Users/test/Desktop/folder | cut -f1

done

echo 'Done'


The until loop is not working because even when the firstSize and the newSize are not equal the loop completes. I am not familiar with writing Bash scripts so I am just making mistakes. This loop is ported over from an applescript I had wrote for the same purpose but I need something more reliable.










share|improve this question



















  • 2




    See How can I assign the output of a command to a shell variable?
    – steeldriver
    Sep 16 at 21:35






  • 1




    Can't you measure the file size rather than the directory size? Could your sending process send the file with a temporary suffix (eg .tmp) and then rename it on successful transfer? (Does OSX have inotify? If so that can provide a far more efficient way of determining that a file has landed.)
    – roaima
    Sep 16 at 21:37










  • Hi @lightwalker. Would you please add more clarifications about what you would like to achieve, so we can help you more efficiently!! How do you transfer your files between folders? do you use rsync, scp, ... ect ? What is the source folder and what is the target folder? Do you want to detect the equality between the source and target folders? let's say that you are using rsync to transfer files between folder A to folder B, let's say the the folders sizes A=B what next? what is the purpose of the script?
    – Goro
    Sep 16 at 21:57










  • Thanks @steeldriver that link helped and it is now working.
    – lightwalker
    Sep 16 at 22:34










  • @roaima thanks, the reason for the folder rather than the file is I have do not have control over the file.
    – lightwalker
    Sep 16 at 22:35












up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I would like to detect when the transfer of a large amount of files is completed. I would like to accomplish this by detecting the size of the folder with a time delay.



Below is what I have done,



 #!/bin/bash

firstSize= du -s /Users/test/Desktop/folder | cut -f1

sleep 3
newSize= du -s /Users/test/Desktop/folder | cut -f1


until [ $firstSize -eq $newSize ]
do
firstSize=$newSize
sleep 3
newSize= du -s /Users/test/Desktop/folder | cut -f1

done

echo 'Done'


The until loop is not working because even when the firstSize and the newSize are not equal the loop completes. I am not familiar with writing Bash scripts so I am just making mistakes. This loop is ported over from an applescript I had wrote for the same purpose but I need something more reliable.










share|improve this question















I would like to detect when the transfer of a large amount of files is completed. I would like to accomplish this by detecting the size of the folder with a time delay.



Below is what I have done,



 #!/bin/bash

firstSize= du -s /Users/test/Desktop/folder | cut -f1

sleep 3
newSize= du -s /Users/test/Desktop/folder | cut -f1


until [ $firstSize -eq $newSize ]
do
firstSize=$newSize
sleep 3
newSize= du -s /Users/test/Desktop/folder | cut -f1

done

echo 'Done'


The until loop is not working because even when the firstSize and the newSize are not equal the loop completes. I am not familiar with writing Bash scripts so I am just making mistakes. This loop is ported over from an applescript I had wrote for the same purpose but I need something more reliable.







shell-script osx






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 16 at 23:36

























asked Sep 16 at 21:22









lightwalker

44




44







  • 2




    See How can I assign the output of a command to a shell variable?
    – steeldriver
    Sep 16 at 21:35






  • 1




    Can't you measure the file size rather than the directory size? Could your sending process send the file with a temporary suffix (eg .tmp) and then rename it on successful transfer? (Does OSX have inotify? If so that can provide a far more efficient way of determining that a file has landed.)
    – roaima
    Sep 16 at 21:37










  • Hi @lightwalker. Would you please add more clarifications about what you would like to achieve, so we can help you more efficiently!! How do you transfer your files between folders? do you use rsync, scp, ... ect ? What is the source folder and what is the target folder? Do you want to detect the equality between the source and target folders? let's say that you are using rsync to transfer files between folder A to folder B, let's say the the folders sizes A=B what next? what is the purpose of the script?
    – Goro
    Sep 16 at 21:57










  • Thanks @steeldriver that link helped and it is now working.
    – lightwalker
    Sep 16 at 22:34










  • @roaima thanks, the reason for the folder rather than the file is I have do not have control over the file.
    – lightwalker
    Sep 16 at 22:35












  • 2




    See How can I assign the output of a command to a shell variable?
    – steeldriver
    Sep 16 at 21:35






  • 1




    Can't you measure the file size rather than the directory size? Could your sending process send the file with a temporary suffix (eg .tmp) and then rename it on successful transfer? (Does OSX have inotify? If so that can provide a far more efficient way of determining that a file has landed.)
    – roaima
    Sep 16 at 21:37










  • Hi @lightwalker. Would you please add more clarifications about what you would like to achieve, so we can help you more efficiently!! How do you transfer your files between folders? do you use rsync, scp, ... ect ? What is the source folder and what is the target folder? Do you want to detect the equality between the source and target folders? let's say that you are using rsync to transfer files between folder A to folder B, let's say the the folders sizes A=B what next? what is the purpose of the script?
    – Goro
    Sep 16 at 21:57










  • Thanks @steeldriver that link helped and it is now working.
    – lightwalker
    Sep 16 at 22:34










  • @roaima thanks, the reason for the folder rather than the file is I have do not have control over the file.
    – lightwalker
    Sep 16 at 22:35







2




2




See How can I assign the output of a command to a shell variable?
– steeldriver
Sep 16 at 21:35




See How can I assign the output of a command to a shell variable?
– steeldriver
Sep 16 at 21:35




1




1




Can't you measure the file size rather than the directory size? Could your sending process send the file with a temporary suffix (eg .tmp) and then rename it on successful transfer? (Does OSX have inotify? If so that can provide a far more efficient way of determining that a file has landed.)
– roaima
Sep 16 at 21:37




Can't you measure the file size rather than the directory size? Could your sending process send the file with a temporary suffix (eg .tmp) and then rename it on successful transfer? (Does OSX have inotify? If so that can provide a far more efficient way of determining that a file has landed.)
– roaima
Sep 16 at 21:37












Hi @lightwalker. Would you please add more clarifications about what you would like to achieve, so we can help you more efficiently!! How do you transfer your files between folders? do you use rsync, scp, ... ect ? What is the source folder and what is the target folder? Do you want to detect the equality between the source and target folders? let's say that you are using rsync to transfer files between folder A to folder B, let's say the the folders sizes A=B what next? what is the purpose of the script?
– Goro
Sep 16 at 21:57




Hi @lightwalker. Would you please add more clarifications about what you would like to achieve, so we can help you more efficiently!! How do you transfer your files between folders? do you use rsync, scp, ... ect ? What is the source folder and what is the target folder? Do you want to detect the equality between the source and target folders? let's say that you are using rsync to transfer files between folder A to folder B, let's say the the folders sizes A=B what next? what is the purpose of the script?
– Goro
Sep 16 at 21:57












Thanks @steeldriver that link helped and it is now working.
– lightwalker
Sep 16 at 22:34




Thanks @steeldriver that link helped and it is now working.
– lightwalker
Sep 16 at 22:34












@roaima thanks, the reason for the folder rather than the file is I have do not have control over the file.
– lightwalker
Sep 16 at 22:35




@roaima thanks, the reason for the folder rather than the file is I have do not have control over the file.
– lightwalker
Sep 16 at 22:35










1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










You messed the commands syntax. The script should look like:



#!/bin/sh -
firstSize=$(du -s /Users/test/Desktop/folder | cut -f1)
until
sleep 3
newSize=$(du -s /Users/test/Desktop/folder | cut -f1)
[ "$firstSize" -eq "$newSize" ]
do
firstSize=$newSize
done
echo 'Done'





share|improve this answer






















    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%2f469438%2fbash-loop-for-detecting-equal-folder-sizes%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    You messed the commands syntax. The script should look like:



    #!/bin/sh -
    firstSize=$(du -s /Users/test/Desktop/folder | cut -f1)
    until
    sleep 3
    newSize=$(du -s /Users/test/Desktop/folder | cut -f1)
    [ "$firstSize" -eq "$newSize" ]
    do
    firstSize=$newSize
    done
    echo 'Done'





    share|improve this answer


























      up vote
      0
      down vote



      accepted










      You messed the commands syntax. The script should look like:



      #!/bin/sh -
      firstSize=$(du -s /Users/test/Desktop/folder | cut -f1)
      until
      sleep 3
      newSize=$(du -s /Users/test/Desktop/folder | cut -f1)
      [ "$firstSize" -eq "$newSize" ]
      do
      firstSize=$newSize
      done
      echo 'Done'





      share|improve this answer
























        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        You messed the commands syntax. The script should look like:



        #!/bin/sh -
        firstSize=$(du -s /Users/test/Desktop/folder | cut -f1)
        until
        sleep 3
        newSize=$(du -s /Users/test/Desktop/folder | cut -f1)
        [ "$firstSize" -eq "$newSize" ]
        do
        firstSize=$newSize
        done
        echo 'Done'





        share|improve this answer














        You messed the commands syntax. The script should look like:



        #!/bin/sh -
        firstSize=$(du -s /Users/test/Desktop/folder | cut -f1)
        until
        sleep 3
        newSize=$(du -s /Users/test/Desktop/folder | cut -f1)
        [ "$firstSize" -eq "$newSize" ]
        do
        firstSize=$newSize
        done
        echo 'Done'






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Sep 17 at 6:47









        Stéphane Chazelas

        287k53528867




        287k53528867










        answered Sep 17 at 5:06









        Romeo Ninov

        4,48321625




        4,48321625



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f469438%2fbash-loop-for-detecting-equal-folder-sizes%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?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay