一、在linux下設(shè)置自動關(guān)機(jī):(服務(wù)器版CentOS-7.2系統(tǒng),硬件:X86平臺) 1.1、關(guān)機(jī)配置腳本路徑: [root@localhost home]# cat /etc/crontab 1.2、關(guān)機(jī)配置腳本內(nèi)容: SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=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 executed 1.3、關(guān)機(jī)配置通過man查詢命令細(xì)節(jié)如下: [root@localhost home]# man 4 crontabs CRONTABS(4) Crontabs users’ Manual CRONTABS(4)
NAME -- crontabs - configuration and scripts for running periodical jobsSYNOPSIS -- run-parts [--list|--test]<directory>DESCRIPTION -- Crontabs is a historical name for the run-parts script and the system crontab. The run-parts script runs all executables in the specified directory.Run-parts runs all by creating file jobs.allow or jobs.deny which worked similar as other allow/deny config files. The file must be created in the specified directory.--list print names of all files (not limited to executables), but don't run them. This option can't be used with test option.--test print names of files, which would be run.Randomization of jobs can be configured in the /etc/sysconfig/run-parts file. To enablerandomization of jobs, set the RANDOMIZE parameterto 1 and set the RANDOM parameter to an integer which determines a random seed. Additionally, you may configure the RANDOMTIME parameter(again, by specifying an integer) to provide an additional level of randomization. Jobs arenot randomized when the RANDOM and RANDOMTIMEparameters are set to 0. Values in these two parameters must be set to 1 or larger to provide agood enough randomization.Randomization of cron jobs can be useful for shared networks, where multiple cron jobs executed at once can cause spikes in traffic, especially during daily jobs. With randomized jobs, the orkload is evenly distributed throughout the day.EXAMPLE OF CONFIGURATION FILERANDOMIZE=1RANDOM=4RANDOMTIME=8Historically the crontab file contained configuration which called run-parts on files in cron.{daily,weekly,monthly} directories. These jobs arenow run indirectly through anacron to prevent conflicts between cron and anacron. That means the anacron package has to be installed if the jobsin these directories should be running. Refer to the anacron(8) how to limit the time of day of the jobexecution.EXAMPLE/etc/cron.daily/jobs.deny could contain for example 0logwatch which forbid execution of this script.SEE ALSOanacron(8), crontab(5)Marcela Ma?láňová 2012-08-29
1.4、實際操作結(jié)果 在命令窗口執(zhí)行:crontab -e 進(jìn)入編輯模式, 依照1.2的提示輸入要執(zhí)行的命令。 CentOS下自帶命令如下: 1.4.1、使用方式: crontab [options] file crontab [options] crontab -n [hostname] 1.4.2、操作選項(1.4.1中的 ‘options’): -u define user 指定執(zhí)行賬戶 -e edit user’s crontab 編輯執(zhí)行命令 -l list user’s crontab 查看可執(zhí)行用戶賬戶 -r delete user’s crontab 刪除某個賬戶的自啟命令 -i prompt before deleting 立即執(zhí)行(不詢問) -n set host in cluster to run users’ crontabs 設(shè)置集群情況下的核心機(jī) -c get host in cluster to run users’ crontabs 集群情況下執(zhí)行核心機(jī)的腳本 -s selinux context 安全模式執(zhí)行 -x enable debugging 允許調(diào)試開機(jī)程序 1.4.3、測試效果: Broadcast message from root@localhost (unknown) at 17:29 … The system is going down for halt NOW! 1.4.4、一些調(diào)試用到的東西: a、crontab依賴linux的開機(jī)自啟服務(wù):crond; b、如果沒有該服務(wù),只要可以執(zhí)行crontab也可以說明已經(jīng)安裝該服務(wù),服務(wù)名可能被隱藏。 c、查看本機(jī)是否支持cronb服務(wù):