Ubuntu timed shutdown command

Source: Internet
Author: User

Source: http://blog.csdn.net/qsd007/archive/2007/04/25/1584872.aspx

1. Shutdown Process

When Linux is running, you cannot directly turn off the power supply. Otherwise, the file system may be damaged.

Therefore, shutdown must follow the normal program:

Observe the system usage (maybe some users are doing important work at the time !)
Notify online users that the local machine will be shut down soon. (if there are many users, you should take a little longer)
Use the correct shutdown command.
The Command Used for shutdown is shutdown.

Shutdown the host system in a safe way.

It notifies all logged-on users that the host is about to be closed and will freeze the login activity.

Shutdown allows you:

Select shutdown, reboot, or enter single-user mode
Set the shutdown time: You can set the current shutdown immediately or set a specific time,
You can customize the warning messages sent to online users before shutdown.
You can send only warning messages to scare users, but you don't really need to shut them down. Sometimes, you may want to do some experiments without disturbing other users.
You can choose whether to use fsck to check the file system
When shutdown starts, the system will send a sigterm signal to notify all the trips (processes), and the host will be shut down soon.

This is necessary because some programs that are running can instantly archive, clear temporary archives, or quickly write data that is still in the memory to the hard drive (flush ).

Shutdown notifies init by message, and requires init to switch runlevel to achieve the above purpose.

If it is halt, switch to runlevel 0; if it is reboot, switch to runlevel 6; if it is single, switch to runlevel 1.

Then, the script file in the runlevel will be handed over to complete the final shutdown.

For details about the runlevel definition, refer to/etc/inittab.

Ii. shutdown command.

/Sbin/shutdown [-T seconds] [-rkhncff] time [warning message]

-T seconds: Set the delay time (in seconds) between the warning and the deletion of two signals before switching to different runlevels ).

-K: only the warning text is sent, but it is not really shutdown.

-R: reboot after shutdown.

-H: shutdown.

-N: shutdown is performed by the shutdown command itself without passing through Init (not recommended)

-F: When the instance is restarted, The fsck command is skipped and the file system is not checked.

-F: force The fsck check when the instance is restarted.

-C: cancels the shutdown operation.

Example:

Shutdown-R now immediately restarts
Shutdown-H now shut down immediately
Shutdown-k now 'Hey! Go away! Now... 'sends a warning message but does not actually shut down
Shutdown-T3-R now immediately restarts, but there is a delay of 3 seconds between the warning and the deletion of processes.
Shutdown-H 10:42 'Hey! Go away! Shut down
Shutdown-r 10' hey! Go away! 'Shutdown in 10 minutes
Shutdown-C cancels the shutdown command. You must switch to another tty to log on before you can run this command.
Shutdown now switch to single-user mode (when no option is added)

Note:

The time parameter must be added: Not now, or hh: mm or mm.
Now actually means 0.

If no option is added, runlevel 1 is displayed, that is, the single-user operation mode.

--------------------------------------------------------------------------------

The shutdown command is as follows. The first is to use shutdown as a task and run automatically every day. The second is to shut down several hours later. You can choose one of them:

Method 1:

You can use the crontab command. Let's take a look at its usage in detail. Name: crontab permission: usage of all users: crontab [-u user] File crontab [-u user] {-L |-r |-e} description: crontab is used to allow users to execute programs at a fixed time or interval. In other words, it is similar to the user's time table. -U user is used to set the time table of the specified user. The premise is that you must have the permission (for example, root) to specify the time table of another user. If-u user is not used, the time table is set.
Meal count:-E: run the text editor to set the time table. The preset text editor is vi. If you want to use another text editor, set the visual environment variable to specify the Text Editor (for example, setenv visual Joe)-R: Delete the current time table-l: the format of the current time series table is as follows: F1 F2 F3 F4 F5 program where F1 represents minutes, F2 represents hours, F3 represents the day of a month, and F4 represents months, f5 indicates the day of the week. Program indicates the program to be executed. When F1 is *, it indicates that execution is performed every minute.
When program and F2 are *, the program is executed every hour, and so on. When F1 is a-B, the program is executed from minute a to minute B, when F2 is a-B, it indicates that execution is performed from hour a to hour B, and so on. When F1 is */N, it indicates that execution is performed every n minutes, if F2 is */N, the task is executed every n hours. Similarly, when F1 is a, B, c ,... a, B, C ,... execute in minutes. F2 is a, B, c ,... a, B, c... the task will be executed in hours, and the other way users can store all the settings in the file first.
In file, use crontab file to set the time table. Example: Execute the command/bin/LS: 0 7 */bin/ls every hour every day from to every day within January 1, 0th, run Once every 20 minutes/usr/bin/backup: 0 6-12/3*12 */usr/bin/backup from Monday to Friday send a letter to alex@domain.name at every day: 0 17 ** 1-5 mail-s "hi" alex@domain.name
</Tmp/maildata 00:20, 02:20, 04:20, and so on every day of the month .... run echo "Haha" 20 0-23/2 *** echo "Haha". Note: When the program is executed at the specified time, the system will send you a letter, display the content of the program execution. If you do not want to receive such a message, add>/dev/null 2> & 1 after each line is empty.

Method 2:

Timed Shutdown

Shutdown: Invalid option ---
Usage: shutdown [-akrhfnc] [-T secs] time [warning message]
-A: Use/etc/shutdown. Allow
-K: Don't Really shutdown, only warn.
-R: reboot after shutdown.
-H: Halt after shutdown.
-F: Do A 'save' reboot (skip fsck ).
-F: Force fsck on reboot.
-N: do not go through "init" but go down real fast.
-C: cancel a running shutdown.
-T secs: delay between warning and kill signal.
** The "time" argument is mandatory! (Try "now ")**

PS: My shutdown-T 54000 is the automatic shutdown after 15 hours of operation.

==============================

Ubuntu can simply use shutdown and its parameters to implement shutdown and other operations, or it can also implement suspension based on command lines.

Sudo pm-hibernate: Sleep
Sudo pm-suspend: suspended
Sudo pm-powersave: power-saving mode

You can use man to view detailed commands.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.