说明:特别注意红色部分,外部$1传入Msg函数时失效,故特此读取一遍再传入!执行时要给脚本加执行权限!#chmod 755 /scripts/svn
[root@kazihuo /scripts]# cat svn
1 #!/bin/bash 2 #by luomurui 2018/05/07 3 4 [ -f /etc/init.d/functions ] && source /etc/init.d/functions 5 6 PID=`ps -ef |grep svnserve|grep -v grep |awk '{print $2}'` 7 ACTION=`echo $1` 8 9 Msg(){ 10 if [ $? -eq 0 ];then 11 action "SVN $ACTION." /bin/true 12 else 13 action "SVN $ACTION." /bin/false 14 fi 15 } 16 17 Start(){ 18 if [[ -z $PID ]];then 19 /usr/bin/svnserve -d -r /svn/svndata/ 20 Msg $1 21 else 22 echo "SVN is running." 23 fi 24 } 25 26 Stop(){ 27 if [[ -n $PID ]];then 28 /bin/kill -9 $PID && sleep 3 29 Msg $1 30 else 31 echo "SVN is not running." 32 fi 33 } 34 35 Restart(){ 36 Stop 37 Start 38 } 39 40 Status(){ 41 if [[ -n $PID ]];then 42 echo "SVN is running." 43 else 44 echo "SVN is not running." 45 fi 46 } 47 48 Usage(){ 49 echo -e "\033[32mUsage:\033[0m $0 {start|stop|restart|status}" 50 } 51 52 Main(){ 53 case "$1" in 54 start) 55 Start 56 ;; 57 stop) 58 Stop 59 ;; 60 restart) 61 Restart 62 ;; 63 status) 64 Status 65 ;; 66 *) 67 Usage 68 ;; 69 esac 70 } 71 72 Main $1
说明:特别注意红色部分,外部$1传入Msg函数时失效,故特此读取一遍再传入!
[root@kazihuo /scripts]# cat svn
#!/bin/bash
#by luomurui 2018/05/07
[ -f /etc/init.d/functions ] && source /etc/init.d/functions
PID=`ps -ef |grep svnserve|grep -v grep |awk '{print $2}'`
ACTION=`echo $1`
Msg(){
if [ $? -eq 0 ];then
action "SVN $ACTION." /bin/true
else
action "SVN $ACTION." /bin/false
fi
}
Start(){
if [[ -z $PID ]];then
/usr/bin/svnserve -d -r /svn/svndata/
Msg $1
else
echo "SVN is running."
fi
}
Stop(){
if [[ -n $PID ]];then
/bin/kill -9 $PID && sleep 3
Msg $1
else
echo "SVN is not running."
fi
}
Restart(){
Stop
Start
}
Status(){
if [[ -n $PID ]];then
echo "SVN is running."
else
echo "SVN is not running."
fi
}
Usage(){
echo -e "\033[32mUsage:\033[0m $0 {start|stop|restart|status}"
}
Main(){
case "$1" in
start)
Start
;;
stop)
Stop
;;
restart)
Restart
;;
status)
Status
;;
*)
Usage
;;
esac
}
Main $1
-------------------------------------------------------------
转载请保留此段声明,且在文章页面明显位置给出原文链接,谢谢!
------------------------------------------------------------------------------
如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!
------------------------------------------------------------------------------