您的位置:首页 > 运维架构 > Linux

Linux命令学习总结:shutdown

2015-01-11 12:42 225 查看
命令简介:该命令可以安全关闭或者重新启动系统。你没有看错,shutdown命令不仅可以关闭系统、也可以重启Linux系统。命令语法:/sbin/shutdown[-tsec][-arkhncfFHP]time[warning-message]命令参数:
参数

长参数

描叙

-a

Use/etc/shutdown.allow.

-c

中断关机:当执行"shutdown-h12:00"指令时,只要按+键就可以中断关机的指令

-f

重新启动时不进行磁盘检测(fsck)

-F

重新启动时进行磁盘检测(fsck)

-h

关闭电源

-k

模拟关机(不是真的关机),只是向登录者发送警告信息出去!

-n

不调用init进程进行关机,而是强行关机

-r

关闭系统然后重新启动,类似于Windows平台restart

-t

延迟关机的时间

-w

仅做测试,并不真的将系统重新开机,只会把重开机的数据写入/var/log目录下的wtmp记录文件

--help

显示命令在线帮助

使用示例:1:查看reboot命令的帮助信息[root@db-server~]#shutdown--help
shutdown:invalidoption---
Usage:shutdown[-akrhHPfnc][-tsecs]time[warningmessage]
-a:use/etc/shutdown.allow
-k:don'treallyshutdown,onlywarn.
-r:rebootaftershutdown.
-h:haltaftershutdown.
-P:haltactionistoturnoffpower.
-H:haltactionistojusthalt.
-f:doa'fast'reboot(skipfsck).
-F:Forcefsckonreboot.
-n:donotgothrough"init"butgodownrealfast.
-c:cancelarunningshutdown.
-tsecs:delaybetweenwarningandkillsignal.
**the"time"argumentismandatory!(try"now")**
[root@db-server~]#

[root@db-server~]#manshutdown
SHUTDOWN(8)LinuxSystemAdministrator鈥檚ManualSHUTDOWN(8)
NAME
shutdown-bringthesystemdown
SYNOPSIS
/sbin/shutdown[-tsec][-arkhncfFHP]time[warning-message]
DESCRIPTION
shutdownbringsthesystemdowninasecureway.Alllogged-inusersarenotifiedthatthesystemisgoing
down,andlogin(1)isblocked.Itispossibletoshutthesystemdownimmediatelyorafteraspecifieddelay.
AllprocessesarefirstnotifiedthatthesystemisgoingdownbythesignalSIGTERM.Thisgivesprogramslike
vi(1)thetimetosavethefilebeingedited,mailandnewsprocessingprogramsachancetoexitcleanly,etc.
shutdowndoesitsjobbysignallingtheinitprocess,askingittochangetherunlevel.Runlevel0isusedto
haltthesystem,runlevel6isusedtorebootthesystem,andrunlevel1isusedtoputtosystemintoastate
whereadministrativetaskscanbeperformed;thisisthedefaultifneitherthe-hor-rflagisgiventoshut-
down.Toseewhichactionsaretakenonhaltorrebootseetheappropriateentriesfortheserunlevelsinthe
file/etc/inittab.
OPTIONS
-aUse/etc/shutdown.allow.
-tsecTellinit(8)towaitsecsecondsbetweensendingprocessesthewarningandthekillsignal,before
changingtoanotherrunlevel.
-kDon鈥檛reallyshutdown;onlysendthewarningmessagestoeverybody.
-rRebootaftershutdown.
-hHaltorpoweroffaftershutdown.
-HHaltactionistohaltordropintobootmonitoronsystemsthatsupportit.
-PHaltactionistoturnoffthepower.
-n[DEPRECATED]Don鈥檛callinit(8)todotheshutdownbutdoitourself.Theuseofthisoptionisdis-
couraged,anditsresultsarenotalwayswhatyou鈥檇expect.
-fSkipfsckonreboot.
-FForcefsckonreboot.
-cCancelanalreadyrunningshutdown.Withthisoptionitisofcoursenotpossibletogivethetimeargu-
ment,butyoucanenteraexplanatorymessageonthecommandlinethatwillbesenttoallusers.
timeWhentoshutdown.
warning-message
Messagetosendtoallusers.
Thetimeargumentcanhavedifferentformats.First,itcanbeanabsolutetimeintheformathh:mm,inwhich
hhisthehour(1or2digits)andmmistheminuteofthehour(intwodigits).Second,itcanbeinthefor-
mat+m,inwhichmisthenumberofminutestowait.Thewordnowisanaliasfor+0.
Ifshutdowniscalledwithadelay,itcreatestheadvisoryfile/etc/nologinwhichcausesprogramssuchas
login(1)tonotallownewuserlogins.Shutdownremovesthisfileifitisstoppedbeforeitcansignalinit
(i.e.itiscancelledorsomethinggoeswrong).Italsoremovesitbeforecallinginittochangetherunlevel.
The-fflagmeans鈥榬ebootfast鈥?Thisonlycreatesanadvisoryfile/fastbootwhichcanbetestedbythesys-
temwhenitcomesupagain.Thebootrcfilecantestifthisfileispresent,anddecidenottorunfsck(1)
sincethesystemhasbeenshutdownintheproperway.Afterthat,thebootprocessshouldremove/fastboot.
The-Fflagmeans鈥榝orcefsck鈥?Thisonlycreatesanadvisoryfile/forcefsckwhichcanbetestedbythesys-
temwhenitcomesupagain.Thebootrcfilecantestifthisfileispresent,anddecidetorunfsck(1)with
aspecial鈥榝orce鈥?flagsothatevenproperlyunmountedfilesystemsgetchecked.Afterthat,thebootprocess
shouldremove/forcefsck.
The-nflagcausesshutdownnottocallinit,buttokillallrunningprocessesitself.shutdownwillthen
turnoffquota,accounting,andswappingandunmountallfilesystems.
ACCESSCONTROL
shutdowncanbecalledfrominit(8)whenthemagickeysCTRL-ALT-DELarepressed,bycreatinganappropriate
entryin/etc/inittab.Thismeansthateveryonewhohasphysicalaccesstotheconsolekeyboardcanshutthe
systemdown.Topreventthis,shutdowncanchecktoseeifanauthorizeduserisloggedinononeofthevir-
tualconsoles.Ifshutdowniscalledwiththe-aargument(addthistotheinvocationofshutdownin/etc/init-
tab),itcheckstoseeifthefile/etc/shutdown.allowispresent.Itthencomparestheloginnamesinthat
filewiththelistofpeoplethatareloggedinonavirtualconsole(from/var/run/utmp).Onlyifoneofthose
authorizedusersorrootisloggedin,itwillproceed.Otherwiseitwillwritethemessage
shutdown:noauthorizedusersloggedin
tothe(physical)systemconsole.Theformatof/etc/shutdown.allowisoneusernameperline.Emptylinesand
commentlines(prefixedbya#)areallowed.Currentlythereisalimitof32usersinthisfile.
Notethatif/etc/shutdown.allowisnotpresent,the-aargumentisignored.
HALTORPOWEROFF
The-HoptionjustsetstheinitenvironmentvariableINIT_HALTtoHALT,andthe-Poptionjustsetsthatvari-
abletoPOWEROFF.Theshutdownscriptthatcallshalt(8)asthelastthingintheshutdownsequenceshould
checktheseenvironmentvariablesandcallhalt(8)withtherightoptionsfortheseoptionstoactuallyhave
anyeffect.Debian3.1(sarge)supportsthis.
FILES
/fastboot
/etc/inittab
/etc/init.d/halt
/etc/init.d/reboot
/etc/shutdown.allow
NOTES
Alotofusersforgettogivethetimeargumentandarethenpuzzledbytheerrormessageshutdownproduces.
Thetimeargumentismandatory;in90percentofallcasesthisargumentwillbethewordnow.
InitcanonlycaptureCTRL-ALT-DELandstartshutdowninconsolemode.IfthesystemisrunningtheXwindow
System,theXserverprocessesallkeystrokes.SomeX11environmentsmakeitpossibletocaptureCTRL-ALT-DEL,
butwhatexactlyisdonewiththateventdependsonthatenvironment.
Shutdownwasn鈥檛designedtoberunsetuid./etc/shutdown.allowisnotusedtofindoutwhoisexecutingshut-
down,itONLYcheckswhoiscurrentlyloggedinon(oneofthe)console(s).
AUTHOR
MiquelvanSmoorenburg,miquels@cistron.nl
SEEALSO
fsck(8),init(8),halt(8),poweroff(8),reboot(8)
November12,2003SHUTDOWN(8)
(END)


2:马上关闭Linux系统,其中now相当于时间为0的状态

[root@db-server~]#shutdown-hnow
Broadcastmessagefromroot(pts/1)(SatJan1018:51:342015):
ThesystemisgoingdownforsystemhaltNOW!

3:系统2分钟后重新启动,其中+m表示几分钟后关机或开机。

[root@db-server~]#shutdown-r+2
Broadcastmessagefromroot(pts/2)(SatJan1019:56:002015):
ThesystemisgoingDOWNforrebootin2minutes!

4:设置系统在那个时间点关机

[root@db-server~]#shutdown-h12:30
[root@db-server~]#shutdown-h12:30&
[1]4578

最好是使用命令&将关机命令至于后台处理。不影响当前其它操作。
设置多久时间后执行shutdown命令。时间参数有hh:mm或+m两种模式。hh:mm格式表示在几点几分执行shutdown命令。例如“shutdown10:45”表示将在10:45执行shutdown.+m表示m分钟后执行shutdown.比较特别的用法是以now表示立即执行shutdown.值得注意的是这部分参数不能省略。另外,需要注意如果现在已经22:30,你执行了shutdown-h22:00&那么第二天才会关机。

5:将前一个shutdown命令取消息

如下所示,执行了下面命令让Linux在12:30关机,但是如果发现这个时间点不合适,那么可以使用CTRL+C取消
[root@db-server~]#shutdown-h12:30

Shutdowncancelled.
[root@db-server~]#
也可以在另外一个命令窗口执行下面命令
[root@db-server~]#shutdown-c

6:向所有登录的用户发出信息

[root@db-server~]#shutdown-k"now"
Broadcastmessagefromroot(pts/2)(SatJan1020:09:142015):
ThesystemisgoingdowntomaintenancemodeNOW!
Shutdowncancelled.

另外登录的会话窗口会收到如下信息

[root@db-server~]#
[root@db-server~]#
Broadcastmessagefromroot(pts/2)(SatJan1020:11:342015):
ThesystemisgoingdowntomaintenancemodeNOW!

一般使用下面语法,如下所示

[root@db-server~]#shutdown-know"TheServerwillshutdownnow"
Broadcastmessagefromroot(pts/1)(SatJan1020:14:542015):
TheServerwillshutdownnow
ThesystemisgoingdowntomaintenancemodeNOW!
Shutdowncancelled.

7:重新启动时不进行磁盘检测

[root@db-server~]#shutdown-frnow
Broadcastmessagefromroot(pts/1)(SatJan1020:23:592015):
ThesystemisgoingdownforrebootNOW!

8:在多少秒后关闭系统并给用户发送提示信息

[root@db-server~]#shutdown-t10-hnow"Systemwillshutdown10sencondlater"
Broadcastmessagefromroot(pts/1)(SatJan1020:33:362015):
Systemwillshutdown10sencondlater
ThesystemisgoingdownforsystemhaltNOW!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: