Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to tell if a Linux machine was hard powered

Posted on 2009-05-08
10
Medium Priority
?
388 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
Independent Software Vendors: 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!

 
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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
Fine Tune your automatic Updates for Ubuntu / Debian
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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

604 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