之前寫(xiě)了開(kāi)機(jī)啟動(dòng)的一個(gè)文章仰税,讓簡(jiǎn)書(shū)給我鎖了...
配置開(kāi)機(jī)啟動(dòng)還挺麻煩的倦畅,這里我寫(xiě)了一個(gè)腳本蹂季,可以將/opt/app.tmux.sh
這個(gè)文件設(shè)置為開(kāi)機(jī)時(shí)執(zhí)行乾闰,這個(gè)文件需要手動(dòng)創(chuàng)建落追,里面執(zhí)行什么內(nèi)容就由你來(lái)定了。如果你想執(zhí)行其它的文件涯肩,將代碼里唯一的/opt/app.tmux.sh
換成其它文件的絕對(duì)路徑即可轿钠。
if [ `whoami` != 'root' ];then
echo "No administrator authority, please use 'root' user."
exit 0
fi
tip(){
echo -e 'Select the following actions:'
echo -e ' s: Set boot startup'
echo -e ' e: exit!'
}
# 開(kāi)機(jī)啟動(dòng),一個(gè)參數(shù)指定開(kāi)機(jī)運(yùn)行哪個(gè)腳本
startup(){
if [ `grep -c 'Alias=rc-local.service' /lib/systemd/system/rc-local.service` > 0 ]; then
echo -e '\n[Install]\nWantedBy=multi-user.target\nAlias=rc-local.service' >> /lib/systemd/system/rc-local.service
fi
if [ ! -f '/etc/systemd/system/rc-local.service' ]; then
ln -s /lib/systemd/system/rc-local.service /etc/systemd/system/
fi
echo -e "#!/bin/bash\nbash $1" > /etc/rc.local
chmod a+x /etc/rc.local
echo -e "done! Startup script has been set: $1 \n\n"
}
control(){
opt='option'
while [ ${opt} != 'e' ]
do
read opt
case ${opt} in
's')
startup '/opt/app.tmux.sh'
;;
'e')
echo -e 'Bye!'
exit 0
;;
*) echo -e 'Wrong choice!\n'
tip
;;
esac
tip
done
}
tip
control
把上面這段代碼保存為init.sh病苗,然后執(zhí)行bash init.sh
即可疗垛,要用root權(quán)限執(zhí)行!