Script to find “How much time taken for Server Reboot?” in Linux

Posted: September 8, 2015 in Amount of Reboot Time, Shell Script

Script : serverreboottime.sh

#!/bin/bash

#script to find out how much time tokk for previous reboot

clear

echo -e “\n\tScript to find How much time taken Linux Server for last Reboot\n”

#BT = Server Boot Time After Reboot
BT=`last -F reboot | head -n 1 | awk ‘{print $5,$6,$7,$8,$9}’`

#RT = Server Rebooted time
RT=`last -F reboot | head -n 2 | awk ‘{print $11,$12,$13,$14,$15}’| tail -1`

echo -e  “Server Boot Time after Reboot = $BT”;
echo -e  “Server Rebooted Time          = $RT”;

#Note below output is should print the value between different date also Example JAN 10 23:59:21 server rebooted again server is came up at JAN 11 00:04:54 it should calculate the difference

echo -e “\nAmount of Time Reboot (seconds)  = $(( $(date -ud “$BT” +’%s’) – $(date -ud “$RT” +’%s’) ))Sec” ;

echo $(( $(date -ud “$BT” +’%s’) – $(date -ud “$RT” +’%s’) )) > out.txt

seconds=`cat /root/out.txt`

echo “Amount of Time Reboot (MM:SS)    = $((seconds/60))Min $((seconds%60))Sec”

echo “Amount of Time Reboot (HH:MM:SS) = $(date -d @$(( $(date -d “$BT” +%s) – $(date -d “$RT” +%s) )) -u +’%H:%M:%S’)”

 

Run :[root@test ~]# ./serverreboottime.sh

 

Output :

Screenshot_1

Comments
  1. Hi there, just became alert to your blog through Google, and found
    that it is truly informative. I am going to watch out for brussels.
    I’ll be grateful if you continue this in future. Lots of people will be benefited from your writing.

    Cheers!

  2. If you wish for to grow your knowledge only keep visiting this web page and be updated with the most up-to-date news update
    posted here.

  3. great post, very informative. I ponder why the opposite specialists of this sector do not understand this.
    You must continue your writing. I’m confident, you have a
    great readers’ base already!

  4. ӏ could not resist commenting. Perfectⅼy written!

  5. Joal says:

    Thank you for your script Keep this work!!

  6. I’m more than happy to uncover this website. I need to to thank you for ones time for this fantastic read!!

    I definitely enjoyed every part of it and
    i also have you saved to fav to see new stuff on your web site.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s