?
Solved

How to tell if a Linux machine was hard powered

Posted on 2009-05-08
10
Medium Priority
?
387 Views
Last Modified: 2013-12-16
I have a retail system that needs to be kept up to date and on at all times unless rebooted by admin. How can I tell if an employee shuts down the machine by pressing the power button or umplugging the power cord.I need to know if the shutdown was gracefull or hard.
0
Comment
Question by:atorex
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +4
10 Comments
 
LVL 22

Expert Comment

by:Syed Mutahir Ali
ID: 24339489
You can check all the boot/shutdown logs in /var/log/messages
This link have some good info : http://www.cyberciti.biz/tips/linux-shutdown-command-and-logfile.html
hope this helps
0
 
LVL 3

Expert Comment

by:SalmanZG
ID: 24339515
Simply use the command:uptime
This will tell you since how long the system has been up.

I got so used to this that I created a script for windows too.
0
 

Author Comment

by:atorex
ID: 24339619
mutahir the link you gave me is good, thanks but I need to know
How can I deferenciate between gracefull and hard shutdown
0
Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

 
LVL 9

Expert Comment

by:KrazyRhino
ID: 24339714
atorex... if there was power removed there would be no log entry as it would not have time to write it.
Combined with the uptime command that salman said it should give you your answer.
0
 
LVL 3

Accepted Solution

by:
SalmanZG earned 2000 total points
ID: 24339974
My mistake for not understanding your question properly.

One easy option is to put a script at run level 6 (shutdown). This will be executed on normal shutdown / reboot and you can append some info to a log file (e.g. 'last reboot') for later analysis.


0
 
LVL 14

Expert Comment

by:Monis Monther
ID: 24340069
Simply use the command last

This is the output from my laptop, its a  fedora 9 , all linux distros have this command, as you can see it tells you when reboots and poweroff happens

[root@server1 ~]# last
root     pts/0        :0.0             Sat May  9 02:17   still logged in  
root     tty1                          Sat May  9 02:16   still logged in  
reboot   system boot  2.6.25-14.fc9.i6 Sat May  9 02:15          (00:26)    
root     pts/0        :0.0             Fri May  8 17:08 - down   (05:47)    
root     tty1                          Fri May  8 17:06 - down   (05:50)    
reboot   system boot  2.6.25-14.fc9.i6 Fri May  8 17:06          (05:50)    
root     pts/0        :0.0             Sat May  2 18:35 - down   (07:15)    
root     tty1                          Sat May  2 18:34 - down   (07:16)    
reboot   system boot  2.6.25-14.fc9.i6 Sat May  2 18:34          (07:17)    

0
 
LVL 14

Expert Comment

by:Monis Monther
ID: 24340074
Another solution would be to attach a UPS and monitor the UPS logs
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 24340091
like small_student suggested, use

last | grep boot
0
 
LVL 19

Expert Comment

by:jools
ID: 24375816
have a lookat `dmidecode` There is a section there that says Wake-Up type, I've only just noticed it so don't know if this is just a "setting" or it is reporting how the system was powered up.

Having said that, I always use the way that ha been mentioned above.


Handle 0x0100, DMI type 1, 25 bytes.
System Information
        Manufacturer: HP
        Product Name: ProLiant DL380 G3
        Version: Not Specified
        Serial Number: BLAHBLAHBLAH
        UUID: Horrible Long string etc.
        Wake-up Type: Power Switch

Open in new window

0
 

Author Closing Comment

by:atorex
ID: 31579607
This looks like the best way to go thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month12 days, 22 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question