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

前端之家收集整理的这篇文章主要介绍了企业Shell面试题15:开发Rsync服务启动脚本案例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

[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

原文链接:https://www.f2er.com/bash/389873.html

猜你在找的Bash相关文章