execute command when a file changes [linux]












2














I have a scenario where I am uploading .csv files to a specific folder /tmp/data_upload everyday and the old files are replaced by the new one,
I need to run a python script once the data is uploaded for this I have an idea to create a cron job and monitor the changes in file i tried using inotify but I am not much in unix domain can anybody help here ?
I need to execute the script test.py once there is a date change of file in upload folder i,e (/tmp/data_upload)










share|improve this question



























    2














    I have a scenario where I am uploading .csv files to a specific folder /tmp/data_upload everyday and the old files are replaced by the new one,
    I need to run a python script once the data is uploaded for this I have an idea to create a cron job and monitor the changes in file i tried using inotify but I am not much in unix domain can anybody help here ?
    I need to execute the script test.py once there is a date change of file in upload folder i,e (/tmp/data_upload)










    share|improve this question

























      2












      2








      2







      I have a scenario where I am uploading .csv files to a specific folder /tmp/data_upload everyday and the old files are replaced by the new one,
      I need to run a python script once the data is uploaded for this I have an idea to create a cron job and monitor the changes in file i tried using inotify but I am not much in unix domain can anybody help here ?
      I need to execute the script test.py once there is a date change of file in upload folder i,e (/tmp/data_upload)










      share|improve this question













      I have a scenario where I am uploading .csv files to a specific folder /tmp/data_upload everyday and the old files are replaced by the new one,
      I need to run a python script once the data is uploaded for this I have an idea to create a cron job and monitor the changes in file i tried using inotify but I am not much in unix domain can anybody help here ?
      I need to execute the script test.py once there is a date change of file in upload folder i,e (/tmp/data_upload)







      linux unix cron automation inotify






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 2 hours ago









      Alex

      112




      112






















          1 Answer
          1






          active

          oldest

          votes


















          2














          You might need incrond (inotify cron daemon) which will monitors changes on files and then execute scripts.



          Incrond can monitor add new file, modify, delete and many more. This is an article shows what event incrond can monitor with some example.



          Example for your case, you might change IN_CREATE,IN_MODIFY to your need



          /tmp/data_upload IN_CREATE,IN_MODIFY test.py 





          share|improve this answer























          • Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
            – Gerald Schneider
            1 hour ago










          • Thanks for reminding me, I have added the context for the link.
            – victoroloan
            1 hour ago












          • Thanks for the answer, just to verify the steps after installing incrontab shoudl execute incrontab -e as root then include this line /tmp/data_upload IN_CREATE,IN_MODIFY test.py ? so that to check once I upload a new file it should execute the test.py file ? where should I place the test.py file ? should i need to provide absolute path for this ?
            – Alex
            37 mins ago










          • I think, It will be better to put the absolute path for your script. You can also check cron or system log if the script seems not working
            – victoroloan
            15 mins ago













          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "2"
          };
          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: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          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%2fserverfault.com%2fquestions%2f947868%2fexecute-command-when-a-file-changes-linux%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          You might need incrond (inotify cron daemon) which will monitors changes on files and then execute scripts.



          Incrond can monitor add new file, modify, delete and many more. This is an article shows what event incrond can monitor with some example.



          Example for your case, you might change IN_CREATE,IN_MODIFY to your need



          /tmp/data_upload IN_CREATE,IN_MODIFY test.py 





          share|improve this answer























          • Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
            – Gerald Schneider
            1 hour ago










          • Thanks for reminding me, I have added the context for the link.
            – victoroloan
            1 hour ago












          • Thanks for the answer, just to verify the steps after installing incrontab shoudl execute incrontab -e as root then include this line /tmp/data_upload IN_CREATE,IN_MODIFY test.py ? so that to check once I upload a new file it should execute the test.py file ? where should I place the test.py file ? should i need to provide absolute path for this ?
            – Alex
            37 mins ago










          • I think, It will be better to put the absolute path for your script. You can also check cron or system log if the script seems not working
            – victoroloan
            15 mins ago


















          2














          You might need incrond (inotify cron daemon) which will monitors changes on files and then execute scripts.



          Incrond can monitor add new file, modify, delete and many more. This is an article shows what event incrond can monitor with some example.



          Example for your case, you might change IN_CREATE,IN_MODIFY to your need



          /tmp/data_upload IN_CREATE,IN_MODIFY test.py 





          share|improve this answer























          • Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
            – Gerald Schneider
            1 hour ago










          • Thanks for reminding me, I have added the context for the link.
            – victoroloan
            1 hour ago












          • Thanks for the answer, just to verify the steps after installing incrontab shoudl execute incrontab -e as root then include this line /tmp/data_upload IN_CREATE,IN_MODIFY test.py ? so that to check once I upload a new file it should execute the test.py file ? where should I place the test.py file ? should i need to provide absolute path for this ?
            – Alex
            37 mins ago










          • I think, It will be better to put the absolute path for your script. You can also check cron or system log if the script seems not working
            – victoroloan
            15 mins ago
















          2












          2








          2






          You might need incrond (inotify cron daemon) which will monitors changes on files and then execute scripts.



          Incrond can monitor add new file, modify, delete and many more. This is an article shows what event incrond can monitor with some example.



          Example for your case, you might change IN_CREATE,IN_MODIFY to your need



          /tmp/data_upload IN_CREATE,IN_MODIFY test.py 





          share|improve this answer














          You might need incrond (inotify cron daemon) which will monitors changes on files and then execute scripts.



          Incrond can monitor add new file, modify, delete and many more. This is an article shows what event incrond can monitor with some example.



          Example for your case, you might change IN_CREATE,IN_MODIFY to your need



          /tmp/data_upload IN_CREATE,IN_MODIFY test.py 






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 1 hour ago

























          answered 1 hour ago









          victoroloan

          563




          563












          • Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
            – Gerald Schneider
            1 hour ago










          • Thanks for reminding me, I have added the context for the link.
            – victoroloan
            1 hour ago












          • Thanks for the answer, just to verify the steps after installing incrontab shoudl execute incrontab -e as root then include this line /tmp/data_upload IN_CREATE,IN_MODIFY test.py ? so that to check once I upload a new file it should execute the test.py file ? where should I place the test.py file ? should i need to provide absolute path for this ?
            – Alex
            37 mins ago










          • I think, It will be better to put the absolute path for your script. You can also check cron or system log if the script seems not working
            – victoroloan
            15 mins ago




















          • Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
            – Gerald Schneider
            1 hour ago










          • Thanks for reminding me, I have added the context for the link.
            – victoroloan
            1 hour ago












          • Thanks for the answer, just to verify the steps after installing incrontab shoudl execute incrontab -e as root then include this line /tmp/data_upload IN_CREATE,IN_MODIFY test.py ? so that to check once I upload a new file it should execute the test.py file ? where should I place the test.py file ? should i need to provide absolute path for this ?
            – Alex
            37 mins ago










          • I think, It will be better to put the absolute path for your script. You can also check cron or system log if the script seems not working
            – victoroloan
            15 mins ago


















          Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
          – Gerald Schneider
          1 hour ago




          Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
          – Gerald Schneider
          1 hour ago












          Thanks for reminding me, I have added the context for the link.
          – victoroloan
          1 hour ago






          Thanks for reminding me, I have added the context for the link.
          – victoroloan
          1 hour ago














          Thanks for the answer, just to verify the steps after installing incrontab shoudl execute incrontab -e as root then include this line /tmp/data_upload IN_CREATE,IN_MODIFY test.py ? so that to check once I upload a new file it should execute the test.py file ? where should I place the test.py file ? should i need to provide absolute path for this ?
          – Alex
          37 mins ago




          Thanks for the answer, just to verify the steps after installing incrontab shoudl execute incrontab -e as root then include this line /tmp/data_upload IN_CREATE,IN_MODIFY test.py ? so that to check once I upload a new file it should execute the test.py file ? where should I place the test.py file ? should i need to provide absolute path for this ?
          – Alex
          37 mins ago












          I think, It will be better to put the absolute path for your script. You can also check cron or system log if the script seems not working
          – victoroloan
          15 mins ago






          I think, It will be better to put the absolute path for your script. You can also check cron or system log if the script seems not working
          – victoroloan
          15 mins ago




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Server Fault!


          • 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.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • 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%2fserverfault.com%2fquestions%2f947868%2fexecute-command-when-a-file-changes-linux%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

          CARDNET

          Boot-repair Failure: Unable to locate package grub-common:i386

          濃尾地震