Skip to content

Simple bash website monitoring script

Moved Tips
  • Not everyone can afford expensive operational monitoring tools, so here’s a cheap and dirty way to use cURL to scrape a webpage, return it’s status, and then compare it with the value you’d get if the page was up. If that doesn’t match, we assume the page is down, and then trigger an email as an alarm.

    #!/bin/bash
    CURLOPT_SSL_VERIFYPEER => 0
    # Your site URL goes here
    website="https://your.forum.url*";
    result=$(curl -m 60 -Is $website | head -n 1 | tr -d "\r")
    # note that this value varies depending on platform. You should echo $result to see what the correct value is when querying the site itself when you know it's running.
    expecting="HTTP/2 200"; 
    timestamp=$(date);
    if [ "$result" = "$expecting" ];
    then
        output="$timestamp -> $website $result -> Website UP";
        echo $output;
        echo $output >> /path/to/your/logfile/log.txt 
    else
        output="$timestamp -> $website $result -> Website DOWN";
        echo $output;
        echo $output >> /path/to/your/logfile/log.txt 
        # Fire an alert as the result isn't what we expected
        mailbody="$output"
        echo "From: email@domain.com" > /tmp/mail.tmp
        echo "To: email@domain.com" >> /tmp/mail.tmp
        echo "Subject: ALERT: Website $website is DOWN" >> /tmp/mail.tmp
        echo "" >> /tmp/mail.tmp
        echo $mailbody >> /tmp/mail.tmp
        cat /tmp/mail.tmp | /usr/sbin/sendmail -t -f "email@domain.com"
    fi
    

    This is very primitive, but works very well. Note, that sendmail is being used here to trigger an email. If you do not have that, you’ll need to substitute the path and command for whatever you want to use.

    Have fun…

  • @phenomlab this is useful 👍 thanks


Related Topics
  • Adding a banner to chat messages

    Tips
    30
    13 Votes
    30 Posts
    2k Views

    Here’s a small modification to the chatBanner function that will place the message just above the composer/reply component meaning it is pinned at the bottom and always in view as a reminder. I’ve made this change to support the threadedChat I’m currently developing

    // Chat message banner function chatBanner() { var roomName = $("h5[component='chat/header/title']").text().trim(); var bannerContent; if (roomName === "Testing 3") { bannerContent = '<div id="chatbanner">This message will fire for chat rooms with the title of "Testing 3"</div>'; } else { bannerContent = '<div id="chatbanner">This session is for <strong>private discussion only</strong> between the chosen participants. Please do <strong>not</strong> place support requests here and create a <a href="#" onclick="app.newTopic();">new topic</a> instead.</div>'; } var chatMessagesContainer = $('[component="chat/system-message"]:last-of-type'); //var existingMessages = $('[component="chat/message"]'); var existingMessages = $('[component="chat/composer"]'); if (existingMessages.length === 0) { // If there are no messages, append the banner to the messages container chatMessagesContainer.first().after(bannerContent); } else { // If there are messages, add the banner after the last message // existingMessages.last().after(bannerContent); existingMessages.before(bannerContent); } }

    There are only two changes here:

    var existingMessages = $('[component="chat/message"]');

    becomes

    var existingMessages = $('[component="chat/composer"]');

    and

    existingMessages.last().after(bannerContent);

    becomes

    existingMessages.before(bannerContent);
  • Unable to change icon in NodeBB navigation

    Tips
    1
    1 Votes
    1 Posts
    163 Views
    No one has replied
  • Google slow to crawl website (Search Console)

    Tips
    6
    3 Votes
    6 Posts
    323 Views

    Seems like Google is finally crawling this site. And, “crawling” in the sense that it’s still extremely slow …

  • Which is Better Samsung S23 or Xiaomi 13

    Tips
    5
    3 Votes
    5 Posts
    269 Views

    @DownPW Same here.

  • 2 Votes
    2 Posts
    262 Views

    As an aside to this, there is also the command of tasklist which will provide a list of processes running on your machine, or a remote machine you are looking to query.

    000a408c-cc7e-450f-8e5e-bed9a4238a05-image.png

    There is also a useful list of switches below, plus the ability to format into a table, or CSV.

    https://ss64.com/nt/tasklist.html

  • Killing Linux Zombie Processes

    Tips
    3
    2 Votes
    3 Posts
    247 Views

    @DownPW odd indeed. Looks like it’s spawning, immediately dying, then spawning again.

  • Google Authenticator for 2FA

    Tips
    7
    6 Votes
    7 Posts
    460 Views

    @crazycells yes, this is something I see on a daily basis and despite how shockingly simple it is to conduct SIM jacking, it seems that several of the USA based banks are reluctant to switch to at least TOTP in the same sense as the USA has been extremely slow to adopt chip and pin - something Europe has been making use of for years.

    And they wonder why cheque and wire fraud is rife in America.

  • Invalid CSRF on dev install

    Moved Solved Tips
    6
    5 Votes
    6 Posts
    3k Views

    @小城风雨多 Looking at the above, it seems you are missing the command to use nodebb for example. Otherwise, you are running the command against the admin database 🙂 Made that mistake myself before…