If you want to hibernate, your Linux machine automatically or want to start it automatically at a specified time for my arrival at the office. To start some process?
Use- ‘rtcwake Command’
# man rtcwakeYou can use this command to either hibernate it now and wake up your Linux machine at a specific time.
you can use it to wake it up after hibernating it at your will (read time) but want the machine to start at a specific time.
Note- I am doing it on ubuntu..
The rtcwake command requires root permissions, so it must be run with sudo on Ubuntu and other Ubuntu-derived distributions. On Linux distributions that don’t use sudo, you’ll have to log in as root with the su command first.
ashu@server:~$ su –
Step-1 Install the rtcwake Package..
root@server:~# apt-get install rtcwake
‘rtcwake’ package successfully Install…
Step- 2 Check & Set The System Hardware Time..
Step- 3 How To Use..
Now use the basic syntax of the command..
root@server:~# rtcwake -m [type of suspend] -s [number of seconds]
(Note– First Check & Set The System Hardware Time..)
Example-1 The following command suspends your system to disk (hibernates it) and wakes it up 60 seconds later:
root@server:~# rtcwake -m disk -s 60
Example-2 For example, to have your computer wake up at 9:30am tomorrow but not suspend immediately (assuming your hardware clock is set to local time), run the following command:
root@server:~# rtcwake -m no -l -t $(date +%s -d “tomorrow 09:30”)
Example-3. Keep on working right now, but once I hibernate at my will. Start the machine again at 6:30PM (OR 18:30PM) Today.
root@server:~# rtcwake -m no -l -t $(date +%s -d “today 06:30”)
Types of Suspend
The -m switch accepts the following types of suspend:
- standby – Standby offers little power savings, but restoring to a running system is very quick. This is the default mode if you omit the -m switch.
- mem – Suspend to RAM. This offers significant power savings – everything is put into a low-power state, except your RAM. The contents of your memory are preserved.
- disk – Suspend to disk. The contents of your memory are written to disk and your computer is powered off. The computer will turn on and its state will be restored when the timer completes.
- off – Turn the computer off completely. rtcwake’s man page notes that restoring from “off” isn’t officially supported by the ACPI specification, but this works with many computers anyway.
- no – Don’t suspend the computer immediately, just set the wakeup time. For example, you could tell your computer to wake up at 6am. After that, can put it to sleep manually at 11pm or 1am – either way, it will wake up at 6am.
Seconds vs. Specific Time
The -s option takes a number of seconds in the future. For example, -s 60 wakes your computer up in 60 seconds, while -s 3600 wakes your computer up in an hour.
The -t option allows you to wake your computer up at a specific time. This switch wants a number of seconds since the Unix epoch (00:00:00 UTC on January 1, 1970). To easily provide the correct number of seconds, combine the date command with the rtcwake command.
The -l switch tells rtcwake that the hardware clock is set to local time, while the -u switch tells rtcwake that the hardware clock (in your computer’s BIOS) is set to UTC time. Linux distributions often set your hardware clock to UTC time and translate that to your local time.
Hibernation in computing is powering down a computer while retaining its state.
Upon hibernation, the computer saves the contents of its random access memory (RAM) to a hard disk or other non-volatile storage. Upon resumption, the computer is exactly as it was upon entering hibernation.
Example- If You want to set, System automacialy go to hibernate mode after 1 minuts Now..
root@server:~# echo ‘pm-hibernate’ | at now + 01 minutes
# vim wake.sh
#To have your computer wake up at 1:30pm today and suspend after 2 Minutes.
rtcwake -m no -l -t $(date +%s -d “today 13:30”)
echo ‘pm-hibernate’ | at now + 02 minutes;exit
# chmod + x wake.sh
Now Your System Power off after 2 Minutes, and System on Automaticaly at 1:30PM…..