How can I continuously run a bash script checking if a value has changed?What is the best way to check if...

How do I compare the result of "1d20+x, with advantage" to "1d20+y, without advantage", assuming x < y?

What are the ramifications of setting ARITHABORT ON for all connections in SQL Server?

Understanding basic photoresistor circuit

Thesis' "Future Work" section – is it acceptable to omit personal involvement in a mentioned project?

Noob at soldering, can anyone explain why my circuit won't work?

Delta TSA-Precheck status removed

How to align underlines in a cases environment

On what legal basis did the UK remove the 'European Union' from its passport?

Is there enough time to Planar Bind a creature conjured by a 1-hour-duration spell?

Why use steam instead of just hot air?

Is there any evidence to support the claim that the United States was "suckered into WW1" by Zionists, made by Benjamin Freedman in his 1961 speech?

Does Lawful Interception of 4G / the proposed 5G provide a back door for hackers as well?

Why do unstable nuclei form?

Ubuntu won't let me edit or delete .vimrc file

How old is Captain America at the end of "Avengers: Endgame"?

On studying Computer Science vs. Software Engineering to become a proficient coder

Renting a house to a graduate student in my department

Was there ever any real use for a 6800-based Apple I?

How to slow yourself down (for playing nice with others)

How do I get past a 3-year ban from overstay with VWP?

Could one theoretically use the expansion of the universe to travel through it? At least in one direction?

Can 'sudo apt-get remove [write]' destroy my Ubuntu?

semanage not changing file context

find not returning expected files



How can I continuously run a bash script checking if a value has changed?


What is the best way to check if file has changed in Bash and keep 15 last copies of it?Can I use an if statement to detect if bash and dash are being run interactively?Is there any major difference when comparing a variable as a string or as an intRunning a timed background job in bashHow do I define alias with variables which can be changed at runtime?How can I launch a command, wait 2 seconds and return the output without killing the command?Bash to Call PHP, Wait for PHP Process to finish?How to pass parameters to function in a bash script?Bash script if statement returning incorrect result while bash -x worksHow make each script run to expect different inner variable value?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







1















I have a PHP script getAnalytics.php that when called, returns a specific integer value. I want to be able to call getAnalytics.php in a bash script that runs continuously checking the PHP script every 30 seconds to see if the value returned has changed.



How would I go about doing this? Or would you recommend a different method?










share|improve this question
















bumped to the homepage by Community 18 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.






















    1















    I have a PHP script getAnalytics.php that when called, returns a specific integer value. I want to be able to call getAnalytics.php in a bash script that runs continuously checking the PHP script every 30 seconds to see if the value returned has changed.



    How would I go about doing this? Or would you recommend a different method?










    share|improve this question
















    bumped to the homepage by Community 18 mins ago


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.


















      1












      1








      1


      1






      I have a PHP script getAnalytics.php that when called, returns a specific integer value. I want to be able to call getAnalytics.php in a bash script that runs continuously checking the PHP script every 30 seconds to see if the value returned has changed.



      How would I go about doing this? Or would you recommend a different method?










      share|improve this question
















      I have a PHP script getAnalytics.php that when called, returns a specific integer value. I want to be able to call getAnalytics.php in a bash script that runs continuously checking the PHP script every 30 seconds to see if the value returned has changed.



      How would I go about doing this? Or would you recommend a different method?







      bash






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 14 '14 at 16:40









      Anthon

      62.1k17109172




      62.1k17109172










      asked Dec 14 '14 at 16:38









      Trey CopelandTrey Copeland

      1062




      1062





      bumped to the homepage by Community 18 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community 18 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
























          2 Answers
          2






          active

          oldest

          votes


















          0














          If you could relax your requirements to a minute between runs, you can easily do this via a cron entry. The advantage of this process is that a program does not simply sit around (and possibly die) causing you to miss some data or window. Also no special steps would be required to start it up between reboots.






          share|improve this answer































            0














            If you have no better indication (watching some log file e.g.) to get notification of a possible change just endlessly loop in bash:



            res=
            while [ 1 ] ; do
            old_result=$res
            res=$(/path/to/getAnalytics.php)
            echo "result: $res"
            if [ "$old_result" != "$res" ]; then
            echo "result has changed"
            fi
            sleep 30
            done


            You will need Ctrl+C to exit. If you want to exit on a particular value (e.g. 42) printed by the script set res to some dummy value at the beginning and then test for [ "$res" != "42" ]






            share|improve this answer


























            • I keep getting /myapp/test.php: line 1: 345234: command not found result,

              – Trey Copeland
              Dec 14 '14 at 16:58











            • @TreyCopeland what happens when you run /myapp/test.php from the commandline? Does that file have a shebang line? If not it is not an executable script and you have to call it with php /myapp/test.php.

              – Anthon
              Dec 14 '14 at 17:21













            • Why while [ 1 ] ; rather than while :; or while true; ?

              – PM 2Ring
              Dec 15 '14 at 6:55











            • @PM2Ring Looks better after 30 years of usage?

              – Anthon
              Dec 15 '14 at 7:08








            • 1





              @PM2Ring I don't think that speed is an issue if the OP can use PHP. And this way, where to put the exit loop with testing on $res requires less explaining.

              – Anthon
              Dec 15 '14 at 7:21












            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',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            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%2f174194%2fhow-can-i-continuously-run-a-bash-script-checking-if-a-value-has-changed%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            If you could relax your requirements to a minute between runs, you can easily do this via a cron entry. The advantage of this process is that a program does not simply sit around (and possibly die) causing you to miss some data or window. Also no special steps would be required to start it up between reboots.






            share|improve this answer




























              0














              If you could relax your requirements to a minute between runs, you can easily do this via a cron entry. The advantage of this process is that a program does not simply sit around (and possibly die) causing you to miss some data or window. Also no special steps would be required to start it up between reboots.






              share|improve this answer


























                0












                0








                0







                If you could relax your requirements to a minute between runs, you can easily do this via a cron entry. The advantage of this process is that a program does not simply sit around (and possibly die) causing you to miss some data or window. Also no special steps would be required to start it up between reboots.






                share|improve this answer













                If you could relax your requirements to a minute between runs, you can easily do this via a cron entry. The advantage of this process is that a program does not simply sit around (and possibly die) causing you to miss some data or window. Also no special steps would be required to start it up between reboots.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 14 '14 at 19:43









                mdpcmdpc

                5,09621838




                5,09621838

























                    0














                    If you have no better indication (watching some log file e.g.) to get notification of a possible change just endlessly loop in bash:



                    res=
                    while [ 1 ] ; do
                    old_result=$res
                    res=$(/path/to/getAnalytics.php)
                    echo "result: $res"
                    if [ "$old_result" != "$res" ]; then
                    echo "result has changed"
                    fi
                    sleep 30
                    done


                    You will need Ctrl+C to exit. If you want to exit on a particular value (e.g. 42) printed by the script set res to some dummy value at the beginning and then test for [ "$res" != "42" ]






                    share|improve this answer


























                    • I keep getting /myapp/test.php: line 1: 345234: command not found result,

                      – Trey Copeland
                      Dec 14 '14 at 16:58











                    • @TreyCopeland what happens when you run /myapp/test.php from the commandline? Does that file have a shebang line? If not it is not an executable script and you have to call it with php /myapp/test.php.

                      – Anthon
                      Dec 14 '14 at 17:21













                    • Why while [ 1 ] ; rather than while :; or while true; ?

                      – PM 2Ring
                      Dec 15 '14 at 6:55











                    • @PM2Ring Looks better after 30 years of usage?

                      – Anthon
                      Dec 15 '14 at 7:08








                    • 1





                      @PM2Ring I don't think that speed is an issue if the OP can use PHP. And this way, where to put the exit loop with testing on $res requires less explaining.

                      – Anthon
                      Dec 15 '14 at 7:21
















                    0














                    If you have no better indication (watching some log file e.g.) to get notification of a possible change just endlessly loop in bash:



                    res=
                    while [ 1 ] ; do
                    old_result=$res
                    res=$(/path/to/getAnalytics.php)
                    echo "result: $res"
                    if [ "$old_result" != "$res" ]; then
                    echo "result has changed"
                    fi
                    sleep 30
                    done


                    You will need Ctrl+C to exit. If you want to exit on a particular value (e.g. 42) printed by the script set res to some dummy value at the beginning and then test for [ "$res" != "42" ]






                    share|improve this answer


























                    • I keep getting /myapp/test.php: line 1: 345234: command not found result,

                      – Trey Copeland
                      Dec 14 '14 at 16:58











                    • @TreyCopeland what happens when you run /myapp/test.php from the commandline? Does that file have a shebang line? If not it is not an executable script and you have to call it with php /myapp/test.php.

                      – Anthon
                      Dec 14 '14 at 17:21













                    • Why while [ 1 ] ; rather than while :; or while true; ?

                      – PM 2Ring
                      Dec 15 '14 at 6:55











                    • @PM2Ring Looks better after 30 years of usage?

                      – Anthon
                      Dec 15 '14 at 7:08








                    • 1





                      @PM2Ring I don't think that speed is an issue if the OP can use PHP. And this way, where to put the exit loop with testing on $res requires less explaining.

                      – Anthon
                      Dec 15 '14 at 7:21














                    0












                    0








                    0







                    If you have no better indication (watching some log file e.g.) to get notification of a possible change just endlessly loop in bash:



                    res=
                    while [ 1 ] ; do
                    old_result=$res
                    res=$(/path/to/getAnalytics.php)
                    echo "result: $res"
                    if [ "$old_result" != "$res" ]; then
                    echo "result has changed"
                    fi
                    sleep 30
                    done


                    You will need Ctrl+C to exit. If you want to exit on a particular value (e.g. 42) printed by the script set res to some dummy value at the beginning and then test for [ "$res" != "42" ]






                    share|improve this answer















                    If you have no better indication (watching some log file e.g.) to get notification of a possible change just endlessly loop in bash:



                    res=
                    while [ 1 ] ; do
                    old_result=$res
                    res=$(/path/to/getAnalytics.php)
                    echo "result: $res"
                    if [ "$old_result" != "$res" ]; then
                    echo "result has changed"
                    fi
                    sleep 30
                    done


                    You will need Ctrl+C to exit. If you want to exit on a particular value (e.g. 42) printed by the script set res to some dummy value at the beginning and then test for [ "$res" != "42" ]







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Dec 14 '14 at 21:28









                    Gilles

                    552k13211291637




                    552k13211291637










                    answered Dec 14 '14 at 16:43









                    AnthonAnthon

                    62.1k17109172




                    62.1k17109172













                    • I keep getting /myapp/test.php: line 1: 345234: command not found result,

                      – Trey Copeland
                      Dec 14 '14 at 16:58











                    • @TreyCopeland what happens when you run /myapp/test.php from the commandline? Does that file have a shebang line? If not it is not an executable script and you have to call it with php /myapp/test.php.

                      – Anthon
                      Dec 14 '14 at 17:21













                    • Why while [ 1 ] ; rather than while :; or while true; ?

                      – PM 2Ring
                      Dec 15 '14 at 6:55











                    • @PM2Ring Looks better after 30 years of usage?

                      – Anthon
                      Dec 15 '14 at 7:08








                    • 1





                      @PM2Ring I don't think that speed is an issue if the OP can use PHP. And this way, where to put the exit loop with testing on $res requires less explaining.

                      – Anthon
                      Dec 15 '14 at 7:21



















                    • I keep getting /myapp/test.php: line 1: 345234: command not found result,

                      – Trey Copeland
                      Dec 14 '14 at 16:58











                    • @TreyCopeland what happens when you run /myapp/test.php from the commandline? Does that file have a shebang line? If not it is not an executable script and you have to call it with php /myapp/test.php.

                      – Anthon
                      Dec 14 '14 at 17:21













                    • Why while [ 1 ] ; rather than while :; or while true; ?

                      – PM 2Ring
                      Dec 15 '14 at 6:55











                    • @PM2Ring Looks better after 30 years of usage?

                      – Anthon
                      Dec 15 '14 at 7:08








                    • 1





                      @PM2Ring I don't think that speed is an issue if the OP can use PHP. And this way, where to put the exit loop with testing on $res requires less explaining.

                      – Anthon
                      Dec 15 '14 at 7:21

















                    I keep getting /myapp/test.php: line 1: 345234: command not found result,

                    – Trey Copeland
                    Dec 14 '14 at 16:58





                    I keep getting /myapp/test.php: line 1: 345234: command not found result,

                    – Trey Copeland
                    Dec 14 '14 at 16:58













                    @TreyCopeland what happens when you run /myapp/test.php from the commandline? Does that file have a shebang line? If not it is not an executable script and you have to call it with php /myapp/test.php.

                    – Anthon
                    Dec 14 '14 at 17:21







                    @TreyCopeland what happens when you run /myapp/test.php from the commandline? Does that file have a shebang line? If not it is not an executable script and you have to call it with php /myapp/test.php.

                    – Anthon
                    Dec 14 '14 at 17:21















                    Why while [ 1 ] ; rather than while :; or while true; ?

                    – PM 2Ring
                    Dec 15 '14 at 6:55





                    Why while [ 1 ] ; rather than while :; or while true; ?

                    – PM 2Ring
                    Dec 15 '14 at 6:55













                    @PM2Ring Looks better after 30 years of usage?

                    – Anthon
                    Dec 15 '14 at 7:08







                    @PM2Ring Looks better after 30 years of usage?

                    – Anthon
                    Dec 15 '14 at 7:08






                    1




                    1





                    @PM2Ring I don't think that speed is an issue if the OP can use PHP. And this way, where to put the exit loop with testing on $res requires less explaining.

                    – Anthon
                    Dec 15 '14 at 7:21





                    @PM2Ring I don't think that speed is an issue if the OP can use PHP. And this way, where to put the exit loop with testing on $res requires less explaining.

                    – Anthon
                    Dec 15 '14 at 7:21


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Unix & Linux Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f174194%2fhow-can-i-continuously-run-a-bash-script-checking-if-a-value-has-changed%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

                    Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

                    Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...