此处参考linux本身的开机脚本模式
会自动开启同目录下 S+两位数字的(S01-zhi) 脚本,并带 start 参数开启;
将各进程的开机脚本按 Sxx 的格式命名即可;
#!/bin/bash
# Start all init scripts in path
# executing them in numerical order.
#
path=`pwd`
for i in $path/S??* ;do
# Ignore dangling symlinks (if any).
[ ! -f "$i" ] && continue
case "$i" in
*.sh)
# Source shell script for speed.
(
trap - INT QUIT TSTP
set start
. $i
)
;;
*)
# No sh extension, so fork subprocess.
$i start
;;
esac
done
demo S01-zhi 内容
#!/bin/bash
case "$1" in
start)
echo zhi-start
;;
stop)
echo zhi-stop
;;
restart)
echo zhi-restart
;;
*)
exit 1
esac
本文介绍了如何利用Linux开机脚本模式,按照S01-z99的顺序自动启动同目录下的shell脚本。通过案例S01-zhi.sh,展示了如何编写和管理这些启动脚本,包括start、stop和restart操作。
1215

被折叠的 条评论
为什么被折叠?



