When Did my Linux Box Last Reboot/ Shutdown?

When Did my Linux Box Last Reboot/ Shutdown?

Get Social!

Linux penguinThe Linux command last can tell you when your Linux system last rebooted, shutdown, who logged in and any runlevel changes.

The utility parses the Linux log file  /var/log/wtmp which contains time stamped entries of these important system events.

The last command is usually installed on most Linux distributions by default and is usually ran as the root user.

Running last on it’s own will display system reboots and user logins with information such as dates, usernames and IP addresses.

last
root     pts/0        10.27.2.100      Thu May 28 00:29   still logged in
root     pts/1        10.27.2.100      Thu May 21 19:55 - 12:02 (5+16:06)
root     pts/0        10.27.2.100      Wed May 20 23:01 - 12:02 (6+13:00)
reboot   system boot  3.18.13+         Wed May 20 23:00 - 00:29 (7+01:29)
root     pts/2        10.27.2.100      Wed May 20 22:43 - down   (00:16)
root     pts/1        10.27.2.100      Wed May 20 16:40 - 16:40  (00:00)
root     pts/0        10.27.2.100      Mon May 18 09:07 - down  (2+13:53)

You can see in the above output that the operating system was last rebooted on the 20th of  May.

There are various switches you can apply to the last command to modify the output. The most common is-x to include runlevel changes and shutdown events in the output.

last -x
root     pts/0        10.27.2.100      Thu May 28 00:29   still logged in
root     pts/1        10.27.2.100      Thu May 21 19:55 - 12:02 (5+16:06)
root     pts/0        10.27.2.100      Wed May 20 23:01 - 12:02 (6+13:00)
runlevel (to lvl 2)   3.18.13+         Wed May 20 23:00 - 00:31 (7+01:30)
reboot   system boot  3.18.13+         Wed May 20 23:00 - 00:31 (7+01:30)
shutdown system down  3.18.7+          Wed May 20 23:00 - 23:00  (00:00)
runlevel (to lvl 6)   3.18.7+          Wed May 20 23:00 - 23:00  (00:00)
root     pts/2        10.27.2.100      Wed May 20 22:43 - down   (00:16)
root     pts/1        10.27.2.100      Wed May 20 16:40 - 16:40  (00:00)
root     pts/0        10.27.2.100      Mon May 18 09:07 - down  (2+13:53)

You can also use last to analyse a log file out of position, such as a logfile you’ve archived. Use the -f switch along with the log file path and name to read it’s data.

last -f /mnt/archive/webserver/wtmp
root     pts/0        10.27.2.100      Thu May 28 00:29   still logged in
root     pts/1        10.27.2.100      Thu May 21 19:55 - 12:02 (5+16:06)
root     pts/0        10.27.2.100      Wed May 20 23:01 - 12:02 (6+13:00)
reboot   system boot  3.18.13+         Wed May 20 23:00 - 00:35 (7+01:34)
root     pts/2        10.27.2.100      Wed May 20 22:43 - down   (00:16)
root     pts/1        10.27.2.100      Wed May 20 16:40 - 16:40  (00:00)
root     pts/0        10.27.2.100      Mon May 18 09:07 - down  (2+13:53)

 


Proxmox OpenVZ Container and KVM Startup and Shutdown Order

Get Social!

proxmox logo gradFrom time to time you will need to shutdown and startup your Proxmox hardware node. There are many reasons for this such as adding new hardware or to apply new kernel updates.

Before you shutdown the hardware node you must cleanly shutdown all OpenVZ containers and all KVMs. To avoid having to do this manually, Proxmox will issue all running containers and VMs the shutdown command as part of the hardware nodes shutdown procedure. Proxmox also gives us the option to specify which containers and VMs should be started when the hardware node is turned on. This means that the final part of the hardware nodes startup sequence will be to start your containers and VMs. Depending on your environment, this may need to be done in a specific order. For example you may wish your database VM or container to be started before your web application.

Enable automatic startup of containers and VMs

To enable the automatic startup of an OpenVZ container or VM you must specify the Start at boot attribute in the Proxmox web interface. Simply click on the Options tab of the container or VM and double click the Start at boot attribute.

proxmox-start-at-boot

Make sure the checkbox is ticked in the new dialogue box which pops up and click OK.

Your container or VM will now automatically be started when your hardware node next starts.

Startup Order for VMs

It is sometimes necessary to specify which containers and VMs startup first and how long the hardware node should wait until issuing the next startup command. This is easy for KVMs as this can be done through the Proxmox web interface.

Simply click on the Options tab of the container or VM and double click the Start/Shutdown order attribute.

proxmox-start-shutdown-order

You can specify the following attributes for the KVM:

  • Start/Shutdown order – this is the order the VMs will be started in. For example, setting this to 1 will mean that this VM will be instructed to start first. You can specify the same number for multiple VMs which means that all VMs of the same number will be instructed to start at the same time. The reverse order is used when the machines are automatically shutdown.
  • Startup delay – this is the time in seconds which Proxmox will wait until moving on to the next priority. If you set a VM with a Start/Shutdown order of 1 with a Startup delay of 30, Proxmox will wait 30 seconds until instructing the VM with a Start/Shutdown order of 2 to start.
  • Shutdown timeout – when a VM is asked to shutdown, an ACPI shutdown request is sent to the VM which should initiate the guests shutdown procedure. If ACPI requests are not supported by the guest, or an exception occurs during shutdown the process may not complete. In this case the Proxmox will wait for the Shutdown timeout threshold to pass before forcefully terminate the VM. If no value is specified then the defaults are used which are 60 seconds for Containers and 180 seconds for VMs.

Any VMs which have the Start at boot attribute enabled but no Start/Shutdown order attribute will be started after all VMs with a Start/Shutdown order attribute set have been processed.

Startup Order for OpenVZ Containers

Unfortunately Proxmox has not provided this functionality in the web based GUI for OpenVZ containers. To specify the order for a container we need to use the command line on the Proxmox hardware node.

Login to your Proxmox hardware node as the root user and issue the below command to set the machine startup order. You will need to change [PRIORITY] to the priority value to use and [VMID] to the ID of the container.

vzctl set [VMID] –bootorder [PRIORITY] -save

You can use vzlist if you do not know the [VMID] of the container.

vzlist

CTID      NPROC STATUS    IP_ADDR         HOSTNAME
100       32    running   -               test.jamescoyle.net

You must have already enabled Start at boot for the container to start up. Any containers which have the Start at boot attribute enabled but no Start/Shutdown order attribute will be started after all containers with a Start/Shutdown order attribute set have been processed.


Restart Windows from the command line

Category : How-to

Get Social!

Windows 7 ShutdownSometimes you may want to restart windows without clicking the Start menu. In some cases, such as in a remote desktop session, the option to restart Windows is missing completely from the Start menu.

You can restart Windows XP/ Windows Server 2003 or newer, using the Windows command line or a shortcut.

shutdown -r -t 10

-r: is the argument to request a restart, rather than a complete shutdown.
-t n: is used to specify a delay, before the restart command will take effect. The default is 60 seconds. ‘n’ represents the time in seconds.

To name a few just a few, you can run this command from the Run dialogue, from a CMD, or from a shorcut.


Visit our advertisers

Quick Poll

How many Proxmox servers do you work with?

Visit our advertisers