Filesystem monitoring












3














A script where we need to come up with a way for the disk space monitoring to be smarter. On smaller file systems, we still want to alert at 90% full, but on larger file sytems, we should only alert when there is only a few GB free.



Can someone please shed some light on this?










share|improve this question





























    3














    A script where we need to come up with a way for the disk space monitoring to be smarter. On smaller file systems, we still want to alert at 90% full, but on larger file sytems, we should only alert when there is only a few GB free.



    Can someone please shed some light on this?










    share|improve this question



























      3












      3








      3







      A script where we need to come up with a way for the disk space monitoring to be smarter. On smaller file systems, we still want to alert at 90% full, but on larger file sytems, we should only alert when there is only a few GB free.



      Can someone please shed some light on this?










      share|improve this question















      A script where we need to come up with a way for the disk space monitoring to be smarter. On smaller file systems, we still want to alert at 90% full, but on larger file sytems, we should only alert when there is only a few GB free.



      Can someone please shed some light on this?







      filesystems monitoring disk-usage






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 19 '18 at 6:27









      Rui F Ribeiro

      39k1479130




      39k1479130










      asked Dec 24 '12 at 2:04









      luckyali

      162




      162






















          2 Answers
          2






          active

          oldest

          votes


















          2














          There is multiple options, but you need modify below script as per your requirement.



          #!/usr/bin/awk -f
          BEGIN{
          ADMIN="root@localhost"
          threshold=20
          "date" | getline date
          "uname -n" | getline hostname

          while("LC_ALL=C df -Ph" | getline){
          used=$5
          if($1 != "Filesystem" && int(used) >= threshold){
          print "Running out of space: "$1,used" used on "hostname" as on: "date
          print "mail -s "Alert: Almost out of disk space: " $1,used" used" "ADMIN" >/dev/null" | "sh"
          close("sh");
          }
          }
          }


          You can refer below links
          http://www.cyberciti.biz/tips/shell-script-to-watch-the-disk-space.html



          http://mmonit.com/monit/



          http://www.linuxjournal.com/content/tech-tip-send-email-alert-when-your-disk-space-gets-low






          share|improve this answer

















          • 2




            Parsing the lines of df will break as soon as the mount reaches a certain amount of characters that df will print it on multiple lines.
            – gertvdijk
            Dec 24 '12 at 8:23






          • 1




            @gertvdijk No, it's ok with df -P, it's designed to be easily parsable (except when device names can contain whitespace).
            – Gilles
            Dec 24 '12 at 17:35










          • @Gilles Good to know that, thanks!
            – gertvdijk
            Dec 24 '12 at 18:13



















          2














          You could (ab)use the Nagios plugin check_disk for this. The advantage is that this piece of software is lightweight, well-tested and probably available by your package management already (Debian/Ubuntu package nagios-plugins-basic). Example usage:



          check_disk -w 10% -c 3 -u GB -p / -p /mnt


          In this example, it checks two mointpoints / and /mnt. If it exits with a exit status of 2, your disk has less than 3GB available, if it exits with status 1, it has less than 10% available and if it exits with a status of 0, then neither of the values is reached. Checking for exit status in Bash is trivial, i.e. $?.






          share|improve this answer





















          • Thanks for your advice.yes we can do it with check_disk nagios plugin. But I would like to write it in shell scripting.
            – user29218
            Dec 24 '12 at 9:58











          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%2f59275%2ffilesystem-monitoring%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









          2














          There is multiple options, but you need modify below script as per your requirement.



          #!/usr/bin/awk -f
          BEGIN{
          ADMIN="root@localhost"
          threshold=20
          "date" | getline date
          "uname -n" | getline hostname

          while("LC_ALL=C df -Ph" | getline){
          used=$5
          if($1 != "Filesystem" && int(used) >= threshold){
          print "Running out of space: "$1,used" used on "hostname" as on: "date
          print "mail -s "Alert: Almost out of disk space: " $1,used" used" "ADMIN" >/dev/null" | "sh"
          close("sh");
          }
          }
          }


          You can refer below links
          http://www.cyberciti.biz/tips/shell-script-to-watch-the-disk-space.html



          http://mmonit.com/monit/



          http://www.linuxjournal.com/content/tech-tip-send-email-alert-when-your-disk-space-gets-low






          share|improve this answer

















          • 2




            Parsing the lines of df will break as soon as the mount reaches a certain amount of characters that df will print it on multiple lines.
            – gertvdijk
            Dec 24 '12 at 8:23






          • 1




            @gertvdijk No, it's ok with df -P, it's designed to be easily parsable (except when device names can contain whitespace).
            – Gilles
            Dec 24 '12 at 17:35










          • @Gilles Good to know that, thanks!
            – gertvdijk
            Dec 24 '12 at 18:13
















          2














          There is multiple options, but you need modify below script as per your requirement.



          #!/usr/bin/awk -f
          BEGIN{
          ADMIN="root@localhost"
          threshold=20
          "date" | getline date
          "uname -n" | getline hostname

          while("LC_ALL=C df -Ph" | getline){
          used=$5
          if($1 != "Filesystem" && int(used) >= threshold){
          print "Running out of space: "$1,used" used on "hostname" as on: "date
          print "mail -s "Alert: Almost out of disk space: " $1,used" used" "ADMIN" >/dev/null" | "sh"
          close("sh");
          }
          }
          }


          You can refer below links
          http://www.cyberciti.biz/tips/shell-script-to-watch-the-disk-space.html



          http://mmonit.com/monit/



          http://www.linuxjournal.com/content/tech-tip-send-email-alert-when-your-disk-space-gets-low






          share|improve this answer

















          • 2




            Parsing the lines of df will break as soon as the mount reaches a certain amount of characters that df will print it on multiple lines.
            – gertvdijk
            Dec 24 '12 at 8:23






          • 1




            @gertvdijk No, it's ok with df -P, it's designed to be easily parsable (except when device names can contain whitespace).
            – Gilles
            Dec 24 '12 at 17:35










          • @Gilles Good to know that, thanks!
            – gertvdijk
            Dec 24 '12 at 18:13














          2












          2








          2






          There is multiple options, but you need modify below script as per your requirement.



          #!/usr/bin/awk -f
          BEGIN{
          ADMIN="root@localhost"
          threshold=20
          "date" | getline date
          "uname -n" | getline hostname

          while("LC_ALL=C df -Ph" | getline){
          used=$5
          if($1 != "Filesystem" && int(used) >= threshold){
          print "Running out of space: "$1,used" used on "hostname" as on: "date
          print "mail -s "Alert: Almost out of disk space: " $1,used" used" "ADMIN" >/dev/null" | "sh"
          close("sh");
          }
          }
          }


          You can refer below links
          http://www.cyberciti.biz/tips/shell-script-to-watch-the-disk-space.html



          http://mmonit.com/monit/



          http://www.linuxjournal.com/content/tech-tip-send-email-alert-when-your-disk-space-gets-low






          share|improve this answer












          There is multiple options, but you need modify below script as per your requirement.



          #!/usr/bin/awk -f
          BEGIN{
          ADMIN="root@localhost"
          threshold=20
          "date" | getline date
          "uname -n" | getline hostname

          while("LC_ALL=C df -Ph" | getline){
          used=$5
          if($1 != "Filesystem" && int(used) >= threshold){
          print "Running out of space: "$1,used" used on "hostname" as on: "date
          print "mail -s "Alert: Almost out of disk space: " $1,used" used" "ADMIN" >/dev/null" | "sh"
          close("sh");
          }
          }
          }


          You can refer below links
          http://www.cyberciti.biz/tips/shell-script-to-watch-the-disk-space.html



          http://mmonit.com/monit/



          http://www.linuxjournal.com/content/tech-tip-send-email-alert-when-your-disk-space-gets-low







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 24 '12 at 6:16









          Rahul Patil

          14.7k186082




          14.7k186082








          • 2




            Parsing the lines of df will break as soon as the mount reaches a certain amount of characters that df will print it on multiple lines.
            – gertvdijk
            Dec 24 '12 at 8:23






          • 1




            @gertvdijk No, it's ok with df -P, it's designed to be easily parsable (except when device names can contain whitespace).
            – Gilles
            Dec 24 '12 at 17:35










          • @Gilles Good to know that, thanks!
            – gertvdijk
            Dec 24 '12 at 18:13














          • 2




            Parsing the lines of df will break as soon as the mount reaches a certain amount of characters that df will print it on multiple lines.
            – gertvdijk
            Dec 24 '12 at 8:23






          • 1




            @gertvdijk No, it's ok with df -P, it's designed to be easily parsable (except when device names can contain whitespace).
            – Gilles
            Dec 24 '12 at 17:35










          • @Gilles Good to know that, thanks!
            – gertvdijk
            Dec 24 '12 at 18:13








          2




          2




          Parsing the lines of df will break as soon as the mount reaches a certain amount of characters that df will print it on multiple lines.
          – gertvdijk
          Dec 24 '12 at 8:23




          Parsing the lines of df will break as soon as the mount reaches a certain amount of characters that df will print it on multiple lines.
          – gertvdijk
          Dec 24 '12 at 8:23




          1




          1




          @gertvdijk No, it's ok with df -P, it's designed to be easily parsable (except when device names can contain whitespace).
          – Gilles
          Dec 24 '12 at 17:35




          @gertvdijk No, it's ok with df -P, it's designed to be easily parsable (except when device names can contain whitespace).
          – Gilles
          Dec 24 '12 at 17:35












          @Gilles Good to know that, thanks!
          – gertvdijk
          Dec 24 '12 at 18:13




          @Gilles Good to know that, thanks!
          – gertvdijk
          Dec 24 '12 at 18:13













          2














          You could (ab)use the Nagios plugin check_disk for this. The advantage is that this piece of software is lightweight, well-tested and probably available by your package management already (Debian/Ubuntu package nagios-plugins-basic). Example usage:



          check_disk -w 10% -c 3 -u GB -p / -p /mnt


          In this example, it checks two mointpoints / and /mnt. If it exits with a exit status of 2, your disk has less than 3GB available, if it exits with status 1, it has less than 10% available and if it exits with a status of 0, then neither of the values is reached. Checking for exit status in Bash is trivial, i.e. $?.






          share|improve this answer





















          • Thanks for your advice.yes we can do it with check_disk nagios plugin. But I would like to write it in shell scripting.
            – user29218
            Dec 24 '12 at 9:58
















          2














          You could (ab)use the Nagios plugin check_disk for this. The advantage is that this piece of software is lightweight, well-tested and probably available by your package management already (Debian/Ubuntu package nagios-plugins-basic). Example usage:



          check_disk -w 10% -c 3 -u GB -p / -p /mnt


          In this example, it checks two mointpoints / and /mnt. If it exits with a exit status of 2, your disk has less than 3GB available, if it exits with status 1, it has less than 10% available and if it exits with a status of 0, then neither of the values is reached. Checking for exit status in Bash is trivial, i.e. $?.






          share|improve this answer





















          • Thanks for your advice.yes we can do it with check_disk nagios plugin. But I would like to write it in shell scripting.
            – user29218
            Dec 24 '12 at 9:58














          2












          2








          2






          You could (ab)use the Nagios plugin check_disk for this. The advantage is that this piece of software is lightweight, well-tested and probably available by your package management already (Debian/Ubuntu package nagios-plugins-basic). Example usage:



          check_disk -w 10% -c 3 -u GB -p / -p /mnt


          In this example, it checks two mointpoints / and /mnt. If it exits with a exit status of 2, your disk has less than 3GB available, if it exits with status 1, it has less than 10% available and if it exits with a status of 0, then neither of the values is reached. Checking for exit status in Bash is trivial, i.e. $?.






          share|improve this answer












          You could (ab)use the Nagios plugin check_disk for this. The advantage is that this piece of software is lightweight, well-tested and probably available by your package management already (Debian/Ubuntu package nagios-plugins-basic). Example usage:



          check_disk -w 10% -c 3 -u GB -p / -p /mnt


          In this example, it checks two mointpoints / and /mnt. If it exits with a exit status of 2, your disk has less than 3GB available, if it exits with status 1, it has less than 10% available and if it exits with a status of 0, then neither of the values is reached. Checking for exit status in Bash is trivial, i.e. $?.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 24 '12 at 8:19









          gertvdijk

          7,24932945




          7,24932945












          • Thanks for your advice.yes we can do it with check_disk nagios plugin. But I would like to write it in shell scripting.
            – user29218
            Dec 24 '12 at 9:58


















          • Thanks for your advice.yes we can do it with check_disk nagios plugin. But I would like to write it in shell scripting.
            – user29218
            Dec 24 '12 at 9:58
















          Thanks for your advice.yes we can do it with check_disk nagios plugin. But I would like to write it in shell scripting.
          – user29218
          Dec 24 '12 at 9:58




          Thanks for your advice.yes we can do it with check_disk nagios plugin. But I would like to write it in shell scripting.
          – user29218
          Dec 24 '12 at 9:58


















          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.





          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%2funix.stackexchange.com%2fquestions%2f59275%2ffilesystem-monitoring%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

          Morgemoulin

          Scott Moir

          Souastre