Linux Timed Shutdown (command tutorial) and linux Shutdown

Source: Internet
Author: User
Tags add time

Linux Timed Shutdown (command tutorial) and linux Shutdown

Go to the following directory

cd /var/spool/cron/

Add time and modify code under this directory

root[root@dev cron]# cat rootSHELL=/bin/bashPATH=/sbin:/bin:/usr/sbin:/usr/binMAILTO=root# For details see man 4 crontabs# Example of job definition:# .---------------- minute (0 - 59)# |  .------------- hour (0 - 23)# |  |  .---------- day of month (1 - 31)# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat# |  |  |  |  |# *  *  *  *  * user-name  command to be executed0 22 * * * root /home/yxd/crontab/shutdown.sh 0 15 * * * root /home/yxd/crontab/mysql_backup.sh [root@dev cron]# cat /home/yxd/crontab/shutdown.sh#!/bin/bashshutdown -h

Shut down

Set in centos7

Format: *** command by hour, day, month, week
# Edit a scheduled task: crontab-e # view the scheduled task list: crontab-l # view the scheduled task execution status: tail-f/var/log/cron

Set Timed Shutdown

1. Press crontab-e and press Enter. 2. Add the task and save it. # Shut Down at pm at a scheduled time. 55 18 ***/sbin/shutdown-h. view the task list crontab-l.

Urgent, cancel Timed Shutdown

Sudo shutdown-c

After modifying the file (after crontab-e is edited, etc wq is saved and exited), restart the service.

systemctl reload crond.service

Currently, the most commonly used commands are added to the/etc/rc. local text file. rc. local is the boot script file.

You can use the crontab command for Timed Shutdown: for example, in rc. the crontab command is added to the local file so that the system will shut down at the specified time after each startup. However, note that the command to shut down at the specified time must be placed in a text file, such as creating a shutdown. place the sh file in the/etc/directory with the following content:

50 22 *** halt-p

That is, shutdown at every day, and then add the following statement to rc. local:

Crontab/etc/shutdown. sh

Another method is to store the directory that requires crontab command execution:/var/spool/cron/

Create a file in the directory (for example, a file named crontabs), and store the commands to be executed, such as the above boot command.

Add:

Users listed in the/etc/cron. deny file cannot use the Crontab command.

Users listed in the/etc/cron. allow file can use the Crontab command.

The following command shows the plan:

Crontab-l

-

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.