Advertisement: Linux VPS for $4/month - based on OpenVZ, credit card accepted, automatic setup.
+ Post New Thread
Results 1 to 2 of 2

Thread: Bash script to meter server downtime in seconds?

  1. #1
    Fli
    Fli is online now
    Administrator Fli's Avatar
    Join Date
    Mar 2013
    Posts
    2,610

    Bash script to meter server downtime in seconds?

    What is the easiest way to discover some server downtime in seconds?

    Im not sure, but there is one script that can help to discover that

    Code:
    remoteserverip=1.2.3.4
    sshport=22
    # ssh access key should be setup in order to connect without password prompts...
    
    # empty countfile
    > count
    
    echo "
    This script will be connecting $serverip each second. Each successfull connection = 1 line in file named $pwd/count. You can run this script in "screen" and durng the runtime, see number of lines (1 second successfull connections) by command: wc -l $pwd/count"
    
    while true ;do
    echo "$(ssh -p $sshport $remoteserverip hostname)" >> count;sleep 1
    done
    
    #
    # this script connects to remote server each second and add remote server hostname to local file named "count".
    # this way we get hostnames one per second, if host is unconnectable, no hostnames will be added
    #
    # run this script like this: timeout 3600s /path/to/script
    # so we run it for one hour and then it is automatically killed
    # then we count number of lines in file "count", so we have rough number of seconds server was connectable
    # the rest number of seconds in 3600 is the approximate downtime. Example after script is interupted after hour, we have 3500 lines in file, that means that approximate downtime during that hour was 100 seconds..
    #
    # need to check downtime of server, in bigger time range like 72 hours? 3600x72=259200s (timeout 259200s)
    please kindly share Your experience or other better ways to get seconds downtime of an server, thx

  2. #2
    Member RuskinF's Avatar
    Join Date
    Jun 2020
    Posts
    68


    Is this useful / helpfull? Yes | No
    You can implement this by overwriting a line. Use \r to go back to the beginning of the line without writing \n to the terminal.

    Write \n when you're done to advance the line.

    Use echo -ne to:

    not print \n and
    to recognize escape sequences like \r.
    Here's a demo:

    echo -ne '##### (33%)\r'
    sleep 1
    echo -ne '############# (66%)\r'
    sleep 1
    echo -ne '####################### (100%)\r'
    echo -ne '\n'

+ Post New Thread

Similar Threads

  1. Replies: 0
    Last Post: 08-19-2017, 09:21 AM
  2. Replies: 0
    Last Post: 04-28-2017, 08:49 AM
  3. Replies: 0
    Last Post: 05-31-2015, 04:16 PM
  4. Replies: 0
    Last Post: 06-20-2014, 09:56 AM
  5. WTS Linux bash script automation service
    By Fli in forum WTS/WTB Programming services
    Replies: 0
    Last Post: 11-08-2013, 12:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
 Protected by : ZB BLOCK  &  StopForumSpam