首页 > 系统服务 > 详细

linux下Shell编程--标准的守护进程的启动脚本

时间:2015-05-18 14:47:02      阅读:230      评论:0      收藏:0      [点我收藏+]

技术分享

技术分享

技术分享技术分享

技术分享技术分享

技术分享技术分享

技术分享技术分享

技术分享

技术分享技术分享

技术分享技术分享

技术分享技术分享

技术分享技术分享

技术分享技术分享

技术分享技术分享

技术分享技术分享

技术分享技术分享

技术分享技术分享



一个标准的守护进程的启动脚本:

#! /bin/sh

WHOAMI=`whoami`
PID=`ps -u $WHOAMI | gerp mydaemond | awk '{print $1}'`

if (test "$1" = "") then
	echo "mydaemond [start][stop][version]"
	exit 0
fi

if ( test "$1" = "status") then
	if ( test "$PID" = "") then	
		echo "not run"
	else
		echo "is running"
	fi
	exit 0
fi	

if (test "$1" = "start") then
	if (test "$PID" = "") then
		./mydaemond
	fi	
	exit 0
fi

if (test "$1" = "stop") then
	if (test "$PID" = "") then
		kill $PID
	fi	
	exit 0
fi

if (test "$1" = "version") then	
	echo "version is V1.0"
	exit 0
fi	

echo "mydaemond [start][stop][version]"

######################################################################################

第一个shell脚本

#! /bin/sh
a=5
b=5
echo a=$a
echo b=$b
if (test "$a" = "$b") then
        echo a=b
else
        echo a!=b
fi

//使用`符号执行一个命令的例子
#! /bin/sh
DATE=`date`
echo "today is" $DATE

//用户输入两个数字,计算两个数字的和
#! /bin/sh
read a
echo 'a=' $a
read b
echo 'b=' $b
c=`expr $a + $b`
echo $c

一个循环5次的例子
#! /bin/sh
times=0
while [ "$times" != "5" ];
do
        echo $times
        times=$[$times + 1]
done

//多重分支的例子
#! /bin/sh
case "$1" in
start)
        echo "is start"
        ;;
stop)
        echo "is stop"
        ;;
*)
        echo "is nothing"
esac



linux下Shell编程--标准的守护进程的启动脚本

原文:http://blog.csdn.net/waldmer/article/details/44851187

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!