Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Need an uptime button/script
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Need an uptime button/script

I'm looking just for a simple button like host-tracker.com provides.
But I'm just looking for a small button which is green if the server is up and red when the server is down. If've already seen the scripts here but these are a bit "overloaded" for me. I hope I explained me problem good enough.

Comments

  • Thanks for the suggestions but that's a bit overloaded for me. I just have a small VPS where already enough services are running. So I wanted to avoid installing php.
    And I wanted to show visitors the button. I'm looking just for a small dot which should change its if the host is down or up.

  • I don't see how you can do this without php. (The servers you are checking don't need anything installed, only the webserver where you host this script)

    See my sig for example, only my dedi got a web server installed.

    Thanked by 1typh0n
  • Maybe there is a website which provides this.
    Do I need anything else to install this? MySql? Can I check if some other services are running too?

  • perennateperennate Member, Host Rep
    edited August 2013

    Well, you can have a cron job that runs every minute, if host is up it does cp green.png button.png or if host is down it does cp red.png button.png.

    So here's an example that should work, if using ping:

    if [ "$(ping -q -c1 yourdomainorip.com)" ]
    then
        cp green.png button.png
    else
        cp red.png button.png
    fi

    Edit: doesn't have to be cron job:

    while :
    do
        if [ "$(ping -q -c1 yourdomainorip.com)" ]
        then
            cp green.png button.png
        else
            cp red.png button.png
        fi
        
        sleep 5
    done
    Thanked by 4typh0n Evo Zen Andre
  • perennateperennate Member, Host Rep
    edited August 2013

    @typh0n said:
    Maybe there is a website which provides this.
    Do I need anything else to install this? MySql? Can I check if some other services are running too?

    If you want more complicated things and still for some reason don't want to install PHP, then you could write a C++ program instead of bash script (although bash probably is just as good if you know how to code it well, I certainly don't :); compile it on your computer and then upload to server, and add it to cron. If you have some specific service in mind, probably external service would be better.

    By the way, in scripts above, you'll need #!/bin/bash to make sure it executes properly.

  • @typh0n said:
    Maybe there is a website which provides this.
    Do I need anything else to install this? MySql? Can I check if some other services are running too?

    You only need a webserver (I would suggest nginx) and PHP. You don't need MySQL or something else.

  • @trexos said:
    You only need a webserver (I would suggest nginx) and PHP. You don't need MySQL or something else.

    Lighty on mine <3

  • Thanks to @perennate for the script! Do you know how I can show the button on my website? What do I need to add to my html code?

  • StrikerrStrikerr Member
    edited August 2013

    @perennate
    Your script always return TRUE.

    if [ "$(ping -q -c1 yourIP | grep "1 received")" ]
    It would be correct.

  • DroidzoneDroidzone Member
    edited August 2013

    @Spirit, I have one too! :D
    http://pinger.droidzone.in

    Once again, php is needed..sorry, OP. You'd probably be better off with somthing like what @perennate wrote.

  • @joelgm I know about your work and it looks damn nice but we can't consider it for usage until release :)

  • I don't know whether it is related to your task, but I had once created a script that runs on the server and keeps logs of its uptime periods (Unix epoch of boot and assumed length of uptime).

  • EvoEvo Member

    @perennate - interesting approach and idea.

  • @Spirit said:
    joelgm I know about your work and it looks damn nice but we can't consider it for usage until release :)

    I'm having difficulties creating a foolproof installer.

  • Check out bash sockets - you can do some neat stuff that goes beyond simple pings/etc

    e.g for a host/port monitor:

    #!/bin/bash
    
    host=$1
    port=$2
    
    if [ "$port" == "" ]; then
      echo ""
      echo "Usage: `basename "$0"` <hostname> <port>"
      echo ""
      exit 0
    fi
    
    timeout 1 bash -c "echo >/dev/tcp/$host/$port" >&/dev/null
    if [ "$?" != 0 ]; then
      echo "${host}:${port} is closed"
    else
      echo "${host}:${port} is open"
    fi
    

    perennate's idea of using an image is a good one so you could throw that in there also. Note that this might not work on Debian unless you've recompiled your bash (I think Debian still compiles bash with –disable-net-redirections by default)

  • @perennate said:

    while :
    > do
    >   if [ "$(ping -q -c1 yourdomainorip.com)" ]
    >   then
    >       cp green.png button.png
    >   else
    >       cp red.png button.png
    >   fi
    >   
    >   sleep 5
    > done

    instead of cp'ing why not just link, less IO :)

    ln -sf green.png button.png

    Thanked by 1typh0n
  • DroidzoneDroidzone Member
    edited August 2013

    Well, I think it's totally unnecessary to copy an image or link an image. You could simply change the style and create a css button. :D

    <span class="statusbtn">Online</span>

    And:
    .statusbtn { color: #FFFFFF; text-align: center; width: 93px; -moz-box-sizing: border-box; display: block; background-image: linear-gradient(to bottom, #269B47, #1CEF58); }

    Produces:

    And do a sed on the stylesheet to replace the color of the indicator.

    Thanked by 1typh0n
  • perennateperennate Member, Host Rep
    edited August 2013

    @Strikerr said:
    perennate
    Your script always return TRUE.

    if [ "$(ping -q -c1 yourIP | grep "1 received")" ]
    It would be correct.

    Ah, I tested it with unknown host, you're right it doesn't send error if it only fails ping. @typh0n you should change to what Strikerr posted.

  • .. and obviously button.png might be cached by your isp, browser, cdn etc. so that might not work

  • perennateperennate Member, Host Rep

    @vampireJ said:
    .. and obviously button.png might be cached by your isp, browser, cdn etc. so that might not work

    .. and obviously you could use sed on HTML to change it instead or add Cache-Control: no-cache or similar header, so it would work.

  • Can you please share the script so that I can host on my end to monitor my VPS?

    @joelgm said:
    Spirit, I have one too! :D
    http://pinger.droidzone.in

    Once again, php is needed..sorry, OP. You'd probably be better off with somthing like what perennate wrote.

  • It's due for release today, probably in the next hour or so. I'm doing the final part of the setup script.

  • Ok, Geekping is officially released.
    Get it here: http://repository.droidzone.in/

  • @vampireJ said:
    .. and obviously button.png might be cached by your isp, browser, cdn etc. so that might not work

    button.png?nocache=$timestamp

  • @typh0n said:
    I'm looking just for a simple button like host-tracker.com provides.
    But I'm just looking for a small button which is green if the server is up and red when the server is down. If've already seen the scripts here but these are a bit "overloaded" for me. I hope I explained me problem good enough.

    SiteUptime.com might work for you, the button doesn't turn red if its down but they e-mail you when its down. free service. 1 site only (they profit off upgrades). ive been using em for 3+ years. i like it.

    button looks like this: http://btn.siteuptime.com/genbutton.php?u=109052&m=90960&c=green&p=total

Sign In or Register to comment.