加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

企业Shell面试题15:开发Rsync服务启动脚本案例

发布时间:2020-12-15 09:20:17 所属栏目:安全 来源:网络整理
导读:[root@oldboy 10-31]# cat backup_rsync.sh #!/bin/bash ############################################################## # File Name: backup_rsync.sh # Version: V1.0 # Author: HU JIN SHENG # Organization: www.oldboyedu.com # Created Time : 2017

[root@oldboy 10-31]# cat backup_rsync.sh

#!/bin/bash

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

# File Name: backup_rsync.sh

# Version: V1.0

# Author: HU JIN SHENG

# Organization: www.oldboyedu.com

# Created Time : 2017-11-01 02:41:11

# Description:

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

. /etc/init.d/functions

case "$1" in

start)

echo "rsync is starting"

rsync --daemon

sleep 2

myport=`netstat -luntp|grep 873|wc -l`

if [ $myport -eq 2 ]

then

action "rsync start" /bin/true

else

action "rsync start" /bin/false

fi

;;

stop)

echo "rsync is stoping"

myport=`netstat -luntp|grep 873|wc -l`

if [ $myport -eq 2 ]

then

killall rsync &>/dev/null

sleep 2

killall rsync &>/dev/null

sleep 1

fi

if [ $myport -ne 2 ]

then

action "rsync stop" /bin/true

else

action "rsync stop" /bin/false

fi

;;

restart)

myport=`netstat -lnt|grep 873|wc -l`

if [ $myport -eq 0 ]

then

rsync --daemon

sleep 2

rsync --daemon

sleep

if [ $myport -eq 2 ]

then

action "restart rsync" /bin/true

else

action "restart rsync" /bin/false

exit

fi

else

killall rsync &>/dev/null

sleep 2

killall rsync &>/dev/null

sleep 1

if [ $myport -eq 2 ]

then

action "rsync restart" /bin/true

else

action "rsync restart" /bin/false

fi

fi

status)

myport=`netstat -lnt|grep 873|wc -l`

if [ $myport -eq 2 ]

then

echo "rsync is running"

else

echo "rsync is stoped"

fi

;;

*)

echo $ "Usage: $0 {start|stop|status|restart} "

;;

esac

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读