Script to check server status from polybar

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 currently running Arch with i3 and polybar. I also maintain 6 servers, so to make my life easier I made a series of shell scripts to notify me if a server is down.



The scripts work, but it's far from an elegant solution. At the moment, I have 2 scripts for each server. One that writes to the status bar (polybar) and one that writes to a log.



This will write to the polybar:



 #!/bin/bash

srv=`ping 000.000.000.000 -c 1 -W 1
| sed '2q;d'
| awk 'NF>1print $NF'`

fail=`date '+%a %H:%M:%S'`



if [[ $srv == ms ]]; then

:

else

echo " 000.000.000.000 | $fail "

fi


This will write to a log file:



 #!/bin/bash

srv=`ping 000.000.000.000 -c 1 -W 1
| sed '2q;d'
| awk 'NF>1print $NF'`

fail=`date '+%a %F %H:%M:%S'`

log1=`ping 000.000.000.000 -c 1 -W 1`

log2=`traceroute 000.000.000.000`

if [[ $srv == ms ]]; then

:

else

echo "<---------------------------------------------->
000.000.000.000 | $fail

----------------------------------------------

$log1

----------------------------------------------

$log2
<---------------------------------------------->



" >> ~/.log/ping.log

fi


Both scripts are added as modules in my polybar config.



I tried having both of these scripts merged as one, but that would make the loading time for the error to show up in polybar too long, so I separated them in to two separate shell scripts.



I added the traceroute to see where the request fails.



I know there has got to be a better way to solve this. A total of 12 shell scripts is just way too much and it's really unefficient. Does anyone have a better solution to this? One that require less shell scripts and will still log in an efficient way?







share|improve this question























    up vote
    0
    down vote

    favorite












    I'm currently running Arch with i3 and polybar. I also maintain 6 servers, so to make my life easier I made a series of shell scripts to notify me if a server is down.



    The scripts work, but it's far from an elegant solution. At the moment, I have 2 scripts for each server. One that writes to the status bar (polybar) and one that writes to a log.



    This will write to the polybar:



     #!/bin/bash

    srv=`ping 000.000.000.000 -c 1 -W 1
    | sed '2q;d'
    | awk 'NF>1print $NF'`

    fail=`date '+%a %H:%M:%S'`



    if [[ $srv == ms ]]; then

    :

    else

    echo " 000.000.000.000 | $fail "

    fi


    This will write to a log file:



     #!/bin/bash

    srv=`ping 000.000.000.000 -c 1 -W 1
    | sed '2q;d'
    | awk 'NF>1print $NF'`

    fail=`date '+%a %F %H:%M:%S'`

    log1=`ping 000.000.000.000 -c 1 -W 1`

    log2=`traceroute 000.000.000.000`

    if [[ $srv == ms ]]; then

    :

    else

    echo "<---------------------------------------------->
    000.000.000.000 | $fail

    ----------------------------------------------

    $log1

    ----------------------------------------------

    $log2
    <---------------------------------------------->



    " >> ~/.log/ping.log

    fi


    Both scripts are added as modules in my polybar config.



    I tried having both of these scripts merged as one, but that would make the loading time for the error to show up in polybar too long, so I separated them in to two separate shell scripts.



    I added the traceroute to see where the request fails.



    I know there has got to be a better way to solve this. A total of 12 shell scripts is just way too much and it's really unefficient. Does anyone have a better solution to this? One that require less shell scripts and will still log in an efficient way?







    share|improve this question





















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I'm currently running Arch with i3 and polybar. I also maintain 6 servers, so to make my life easier I made a series of shell scripts to notify me if a server is down.



      The scripts work, but it's far from an elegant solution. At the moment, I have 2 scripts for each server. One that writes to the status bar (polybar) and one that writes to a log.



      This will write to the polybar:



       #!/bin/bash

      srv=`ping 000.000.000.000 -c 1 -W 1
      | sed '2q;d'
      | awk 'NF>1print $NF'`

      fail=`date '+%a %H:%M:%S'`



      if [[ $srv == ms ]]; then

      :

      else

      echo " 000.000.000.000 | $fail "

      fi


      This will write to a log file:



       #!/bin/bash

      srv=`ping 000.000.000.000 -c 1 -W 1
      | sed '2q;d'
      | awk 'NF>1print $NF'`

      fail=`date '+%a %F %H:%M:%S'`

      log1=`ping 000.000.000.000 -c 1 -W 1`

      log2=`traceroute 000.000.000.000`

      if [[ $srv == ms ]]; then

      :

      else

      echo "<---------------------------------------------->
      000.000.000.000 | $fail

      ----------------------------------------------

      $log1

      ----------------------------------------------

      $log2
      <---------------------------------------------->



      " >> ~/.log/ping.log

      fi


      Both scripts are added as modules in my polybar config.



      I tried having both of these scripts merged as one, but that would make the loading time for the error to show up in polybar too long, so I separated them in to two separate shell scripts.



      I added the traceroute to see where the request fails.



      I know there has got to be a better way to solve this. A total of 12 shell scripts is just way too much and it's really unefficient. Does anyone have a better solution to this? One that require less shell scripts and will still log in an efficient way?







      share|improve this question











      I'm currently running Arch with i3 and polybar. I also maintain 6 servers, so to make my life easier I made a series of shell scripts to notify me if a server is down.



      The scripts work, but it's far from an elegant solution. At the moment, I have 2 scripts for each server. One that writes to the status bar (polybar) and one that writes to a log.



      This will write to the polybar:



       #!/bin/bash

      srv=`ping 000.000.000.000 -c 1 -W 1
      | sed '2q;d'
      | awk 'NF>1print $NF'`

      fail=`date '+%a %H:%M:%S'`



      if [[ $srv == ms ]]; then

      :

      else

      echo " 000.000.000.000 | $fail "

      fi


      This will write to a log file:



       #!/bin/bash

      srv=`ping 000.000.000.000 -c 1 -W 1
      | sed '2q;d'
      | awk 'NF>1print $NF'`

      fail=`date '+%a %F %H:%M:%S'`

      log1=`ping 000.000.000.000 -c 1 -W 1`

      log2=`traceroute 000.000.000.000`

      if [[ $srv == ms ]]; then

      :

      else

      echo "<---------------------------------------------->
      000.000.000.000 | $fail

      ----------------------------------------------

      $log1

      ----------------------------------------------

      $log2
      <---------------------------------------------->



      " >> ~/.log/ping.log

      fi


      Both scripts are added as modules in my polybar config.



      I tried having both of these scripts merged as one, but that would make the loading time for the error to show up in polybar too long, so I separated them in to two separate shell scripts.



      I added the traceroute to see where the request fails.



      I know there has got to be a better way to solve this. A total of 12 shell scripts is just way too much and it's really unefficient. Does anyone have a better solution to this? One that require less shell scripts and will still log in an efficient way?









      share|improve this question










      share|improve this question




      share|improve this question









      asked Jun 14 at 18:30









      discipulus

      264




      264

























          active

          oldest

          votes











          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%2f449878%2fscript-to-check-server-status-from-polybar%23new-answer', 'question_page');

          );

          Post as a guest



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes










           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f449878%2fscript-to-check-server-status-from-polybar%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