Solved

How to tell if a Linux machine was hard powered

Posted on 2009-05-08
10
380 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
  • 2
  • 2
  • 2
  • +4
10 Comments
 
LVL 22

Expert Comment

by:mutahir
Comment Utility
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
Comment Utility
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
Comment Utility
mutahir the link you gave me is good, thanks but I need to know
How can I deferenciate between gracefull and hard shutdown
0
 
LVL 9

Expert Comment

by:KrazyRhino
Comment Utility
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 500 total points
Comment Utility
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
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 
LVL 14

Expert Comment

by:small_student
Comment Utility
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:small_student
Comment Utility
Another solution would be to attach a UPS and monitor the UPS logs
0
 
LVL 40

Expert Comment

by:omarfarid
Comment Utility
like small_student suggested, use

last | grep boot
0
 
LVL 19

Expert Comment

by:jools
Comment Utility
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
Comment Utility
This looks like the best way to go thanks
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
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.

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now