首页 > 系统服务 > 详细

兄弟连 企业shell笔试题 16-31

时间:2017-12-05 00:21:22      阅读:271      评论:0      收藏:0      [点我收藏+]

企业实践题16:
企业案例:写网络服务独立进程模式下rsync的系统启动脚本

例如:/etc/init.d/rsyncd{start|stop|restart} 。
要求:
1.要使用系统函数库技巧。
2.要用函数,不能一坨SHI的方式。
3.可被chkconfig管理。

脚本1:

#!/bin/bash

pidfile="/var/run/rsyncd.pid"
result=`ps aux|grep rsync|grep -v ‘grep‘` 

Rstatus(){

if [ $resultX == X ];then
 echo "rsyncd is down"
else
 echo "rsyncd is running"
fi

}


Rstart(){

if [ $resultX == X ];then
 /usr/bin/rsync --daemon --config=/etc/rsyncd/rsyncd.conf 
else
 echo "rsyncd is running"
fi
}

 

Rstop(){
if [ $resultX == X ];then
   echo "rsync service is not running !" 
   exit 1
else
 
kill -9 $(cat $pidfile)
 Rstatus2=`$(ps -ef | egrep "rsync --daemon.*rsyncd.conf" | grep -v ‘grep‘)`
 if [ $RstatusX = X ];then
   rm -f $pidfile
   echo "rsync service stop.......OK" 
 fi 
fi

}

Rrestart(){
 Rstop
 Rstart
}

 

兄弟连 企业shell笔试题 16-31

原文:http://www.cnblogs.com/centos2017/p/7979479.html

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