Command That Gives Booting Times


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Command That Gives Booting Times
# 8  
Old 10-23-2010
Ah ha! Thank you for this unexpected enlightenment.

Then let me diverge from the problem statement to mention something I have done that provides similar information for my own use and amusement.

I wrote a bash script that cron runs every morning. Here is what it does:
  • Parse the output of uptime to see how many days the system has been running
  • Parse the last line of of my uptime log to see the last number of days logged
  • If today's uptime is longer than in the last line, delete the last line
  • Append a line with today's date and the number of days up
The result is a log file that lists how many days I had been running each time I shutdown or rebooted.

I didn't know about the last command. That's kind of interesting, though I'm not sure it will be of use to me.
# 9  
Old 10-23-2010
In the commercial world remember that "last" reads the "wtmp" file. This file is well known for growing rapidly so many administrators age the file say weekly and keep a couple of months worth.

A reliable unix system may be up for more than a year. Even if you don't age the "wtmp" file bear in mind that "who -b" doesn't say which year!
# 10  
Old 11-02-2010
solution

solution for this problem:

Code:
if [ -z "$1" ]   # if there is no input
then
    echo "enter the number of days"
exit 0
fi


touch rebootSwap.txt
last reboot > rebootSwap.txt
number=$1
for (( i=0; i<$number; i++ ));
do
tempDate=`date --date="$i days ago" '+%b %d'`     # makes the temp day i days ago  in %b %d format
CurrentCount=`grep -i "$tempDate" rebootSwap.txt | wc -l` # search the temp day in text
DATE=$(date -d "$tempDate" +"%d/%m/%y")          


echo "$DATE booted $CurrentCount times" # print the date and boot count
done
rm rebootSwap.txt


Last edited by radoulov; 11-02-2010 at 02:10 PM.. Reason: Code tags, please!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed command to replace one value which occurs multiple times

Hi, My Input File : "MN.1.2.1.2.14.1.1" := "MN_13_TM_4" ( 000000110110100100110001111110110110101110101001100111110100011010110111001 ) "MOS.1.2.1.2.13.6.2" := "MOS_13_TM_4" ( 000000110110100100110001111110110110101110101001100111110100011010110111001 ) Like above template,I have... (4 Replies)
Discussion started by: Preeti Chandra
4 Replies

2. Red Hat

Systemd booting and execute system command is Not successful!help!

hi guys, booting centos7 and use systemd execute system command ulimit -SHn 202400 is fail.i dont know what's reason.can you give me help. ------------------------------------------ set-ulimit.service Description=test service After=systemd-update-utmp-runlevel.service #the last... (1 Reply)
Discussion started by: shean
1 Replies

3. SCO

Booting to Command Prompt

Hello, I need help booting to a command prompt. The server runs SCO Openserver 5.0, with a point of sale program that automatically boots upon startup. I can't gain root access, and the administrator password for the point of sale program is un-obtainable. I am upgrading to a new point of sale... (8 Replies)
Discussion started by: tedcurvin
8 Replies

4. Shell Programming and Scripting

Script runs in command-line fine but times out in CRON?

Hi, I have a script that seems to run to completion when in the command-line, but when it is run using the cron, it seems to time out. They both start and run fine, but on the CRON it stops prematurely. The script hits an API every few seconds and grabs data. Does anyone have any idea on... (4 Replies)
Discussion started by: phpchick
4 Replies

5. Programming

Problem with implementing the times() function in C (struct tms times return zero/negative values)

Hello, i'm trying to implement the times() function and i'm programming in C. I'm using the "struct tms" structure which consists of the fields: The tms_utime structure member is the CPU time charged for the execution of user instructions of the calling process. The tms_stime structure... (1 Reply)
Discussion started by: g_p
1 Replies

6. Shell Programming and Scripting

How to implement a command n times?

I need to run a command n (n >= 100) times and the command running may take about 30 seconds. Can anyone help me with the shell script to achieve this? Thanks in advance. (5 Replies)
Discussion started by: zwei2011
5 Replies

7. Shell Programming and Scripting

Run .command at specific times

Okay so I've got a command to start my java server up, but I want it to start at say 8:00AM and then stop at 11:00PM. In order to stop it I have to type stop and press enter in the terminal. I've been trying to get this to work and I'm having no luck. Here's my command: #!/bin/bash cd "`dirname... (2 Replies)
Discussion started by: JustChillin1414
2 Replies

8. AIX

how would you know your server was rebooted 3 times or 5 times

Is there such location or command to know how many times did you reboot your server in that particular day?in AIX. (3 Replies)
Discussion started by: kenshinhimura
3 Replies

9. Solaris

booting from CD

Hello.. I am Still Learing Solaris .. when i try to Install Solaris 8 from its CD...i pressed STOP + A and i get a OK prompt screen. I then typed, "boot cdrom" and i am getting this error message. " FATAL: system is not bootable, boot command is disabled." How do we enable the boot... (5 Replies)
Discussion started by: vr76413
5 Replies

10. Shell Programming and Scripting

How to make my command work at all times

hi all, This is a very basic question. I want to make the command work at all times. i'm working on Suse-Linux and "clear" command is used to clear the contents of screen. I want to use only "cls" instead of "clear" command. i tried alias cls=clear , but its working only for a temporary... (3 Replies)
Discussion started by: wxwidgets
3 Replies
Login or Register to Ask a Question