注:實驗發現關機及其重啟後執行的指令碼的指令碼中不能巢狀呼叫其它指令碼。
該指令碼需要應該與服務程式中execstart項相對應。及該指令碼名為/home/lhx/reboot.sh
且需要安裝expectyum install expect
vim /home/lhx/reboot.sh
#!/bin/bash
passwd="123456"
echo "shutdown or reboot at `date +'%y%m%d%h%m'`" >> /home/redflag/mock/reboot.log
/usr/bin/expect <<-eof
spawn rsync -arv /home/redflag/mock/ [email protected]:/home/liuhuaxian/bak/mock
expect "*password"
send "123456\n"
expect eof
eof
vi /usr/lib/systemd/system/rebootsrv.service
[unit]
description=close services before reboot and shutdown
defaultdependencies=no
before=shutdown.target reboot.target halt.target
[service]
type=oneshot
execstart=/home/lhx/reboot.sh #your path and filename
[install]
wantedby=halt.target reboot.target shutdown.target
然後執行
[root@localhost lhx]# systemctl enable rebootsrv.service
created symlink from /etc/systemd/system/halt.target.wants/rebootsrv.service to /usr/lib/systemd/system/rebootsrv.service.
created symlink from /etc/systemd/system/reboot.target.wants/rebootsrv.service to /usr/lib/systemd/system/rebootsrv.service.
created symlink from /etc/systemd/system/shutdown.target.wants/rebootsrv.service to /usr/lib/systemd/system/rebootsrv.service.
重啟關機後就能自動執行/home/lhx/reboot.sh
該指令碼。 centos7系統關機命令 Linux關機命令介紹
init init是所有程序的祖先 它的程序號始終為1 所以傳送term訊號給init會終止所有的使用者程序 守護程序等。shutdown 就是使用這種機制。init定義了8個執行級別 runlevel init 0為關機 init 1為重啟。關於init可以長篇大論 這裡就不再敘述。另外還有tel...
centos7正確關機重啟
linux主要用於伺服器領域,而在伺服器上執行一項服務是永無止境的,除非遇到特殊情況,否則不會關機。和windows不同,在linux系統下,很多程序是在後台執行的。在螢幕背後,可能有很多人同時在工作。如果直接按下電源的按鈕,其他人的資料可能就此中斷。更嚴重的是,若不正常關機,嚴重的話,可能會造成檔...
centos7 異常關機 分析。
這台伺服器配置為雙路e5 6碟符raid1 0陣列,虛擬磁碟835.491gb sas15000rpm硬碟 4g 記憶體,估計看見記憶體大小你們笑噴了,奇葩的組合,任性的主機。之前此台伺服器安裝esxi帶一台虛擬機器,經常無故宕機,系統日誌也沒有記錄。後來直接裝了物理機centos 7,emm仍舊宕...