Find the answer to your Linux question:
Results 1 to 4 of 4
Hi, I need to find the last system shutdown time. I got a command last that is used for this.But the command is not give the year. Below i posted ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Dec 2010
    Posts
    3

    Find last system shut down time


    Hi,

    I need to find the last system shutdown time. I got a command last that is used for this.But the command is not give the year. Below i posted the sample output

    Sample output:

    last -x | grep shutdown
    shutdown system down 2.6.31.5-server- Tue Jan 11 11:45 - 11:46 (00:00)
    shutdown system down 2.6.31.5-server- Sat Dec 11 11:25 - 11:45 (31+00:20)
    shutdown system down 2.6.31.5-server- Mon Jan 10 21:04 - 10:31 (13:27)
    shutdown system down 2.6.31.5-server- Fri Jan 7 17:38 - 11:05 (2+17:26)
    shutdown system down 2.6.31.5-server- Thu Jan 6 20:39 - 10:00 (13:21)
    shutdown system down 2.6.31.5-server- Wed Jan 5 19:48 - 10:46 (14:5
    shutdown system down 2.6.31.5-server- Tue Jan 4 20:13 - 09:51 (13:3


    year field is important for me. how can i get that or is any command is used to get the system last down time in Linux?

    Guide me.

  2. #2
    Just Joined!
    Join Date
    Jan 2011
    Posts
    4
    Well, as you found out the last command doesn't include the year which is unfortunate. This means you will have to find a way to parse the /var/log/wtmp file yourself. It's not a text file so it's going to require some special handling.

    A little googling turned up the following three page article that should give you an idea on how to get the data your looking for out of the /var/log/wtmp file. I read through it and learned a few things myself. I'm not well versed in perl but it was suggested to read the free online chapter from "Perl for System Administration" for even better ways to handle wtmp. Good luck on that. Here is the article:

    Code:
    wtf.itworld.com/nls_unixlastlogin050331?page=0%2C0
    It would appear that I am restricted from posting links to websites hence the wtf misspelling. Just trying to help.

  3. #3
    Linux User sgosnell's Avatar
    Join Date
    Oct 2010
    Location
    Baja Oklahoma
    Posts
    482
    Use -F to get the full date and time. It's presented in a slightly different format than just using -x, but it does give the year. "man last" gives more detail.

  4. #4
    Just Joined!
    Join Date
    Mar 2012
    Posts
    1

    now if i want to store this detail in a file automatically how should/

    now if i want to store this detail in a file automatically how should/







    Quote Originally Posted by emily_glover View Post
    Hi,

    I need to find the last system shutdown time. I got a command last that is used for this.But the command is not give the year. Below i posted the sample output

    Sample output:

    last -x | grep shutdown
    shutdown system down 2.6.31.5-server- Tue Jan 11 11:45 - 11:46 (00:00)
    shutdown system down 2.6.31.5-server- Sat Dec 11 11:25 - 11:45 (31+00:20)
    shutdown system down 2.6.31.5-server- Mon Jan 10 21:04 - 10:31 (13:27)
    shutdown system down 2.6.31.5-server- Fri Jan 7 17:38 - 11:05 (2+17:26)
    shutdown system down 2.6.31.5-server- Thu Jan 6 20:39 - 10:00 (13:21)
    shutdown system down 2.6.31.5-server- Wed Jan 5 19:48 - 10:46 (14:5
    shutdown system down 2.6.31.5-server- Tue Jan 4 20:13 - 09:51 (13:3


    year field is important for me. how can i get that or is any command is used to get the system last down time in Linux?

    Guide me.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •