Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 389
  • Last Modified:

How to tell if a Linux machine was hard powered

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
atorex
Asked:
atorex
  • 2
  • 2
  • 2
  • +4
1 Solution
 
Syed Mutahir AliTechnology ConsultantCommented:
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
 
SalmanZGCommented:
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
 
atorexAuthor Commented:
mutahir the link you gave me is good, thanks but I need to know
How can I deferenciate between gracefull and hard shutdown
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
KrazyRhinoCommented:
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
 
SalmanZGCommented:
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
 
Monis MontherSystem ArchitectCommented:
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
 
Monis MontherSystem ArchitectCommented:
Another solution would be to attach a UPS and monitor the UPS logs
0
 
omarfaridCommented:
like small_student suggested, use

last | grep boot
0
 
joolsCommented:
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
 
atorexAuthor Commented:
This looks like the best way to go thanks
0

Featured Post

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!

  • 2
  • 2
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now