shell框架,


#!/bin/bash
#注释
#注释
#环境变量相关,如下
PATH=/sbin:/bin:/usr/bin:/usr/sbin

#引入库函数,如下,类似于c语言的#include "*.h"

. /etc/init.d/functions

#获取相关配置信息,不是必须的,如
test -f /etc/sysconfig/network && . /etc/sysconfig/network

#判断是否是root用户,如果不是就退出
[ `id -u` = 0 ] || exit 1

#定义本地变量,如
prog="xinetd"

#定义shell函数,如
stop(){
echo -n $"Stopping $prog: "
killproc $prog
RETVAL=$?
echo
rm -f /var/lock/subsys/xinetd
return $RETVAL

}

#shell脚本主框架,一般是一个case结构或者循环结构
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status $prog
;;
restart)
restart
;;
reload)
reload
;;
condrestart)
condrestart
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
RETVAL=1
esac
#退出

相关内容

    暂无相关文章