开发rsync启动脚本2

使用函数更加规范的开发rsync启动脚本

#!/bin/bash
#chkconfig: 2345 20  80
#description: create by vincen

. /etc/init.d/functions

function usage(){
        echo $"usage:$0 {start|stop|restart}"
        exit 1
}

function start(){
        rsync --daemon
        sleep 1
        if [ `netstat -lntup|grep rsync|wc -l` -ge 1 ];then
                action "rsyncd is started." /bin/true
        else
                action "rsyncd is started." /bin/false
        fi
}

function stop(){
        killall rsync
        sleep 1
        if [ `netstat -lntup|grep rsync|wc -l` -eq 0 ];then
                action "rsyncd is stopped." /bin/true
        else
                action "rsync is started." /bin/false
        fi
}

function main(){
        if [ $# -ne 1 ];then
                usage
        fi
        if [ "$1" == "start" ];then
                start
        elif [ "$1" == "stop" ];then
                stop
        elif [ "$1" == "restart" ];then
                stop
                sleep 1
                start
        else
                usage
        fi
}
main $*

执行结果:

[[email protected] script]# /etc/init.d/rsyncd start
rsyncd is started.                                         [  OK  ]
[[email protected] script]# vim /etc/init.d/rsyncd
[[email protected] script]# /etc/init.d/rsyncd start
rsyncd is started.                                         [  OK  ]
[[email protected] script]# /etc/init.d/rsyncd stop
rsyncd is stopped.                                         [  OK  ]
[[email protected] script]# /etc/init.d/rsyncd restart
rsync: no process killed
rsyncd is stopped.                                         [  OK  ]
rsyncd is started.                                         [  OK  ]
时间: 2024-08-04 23:01:24

开发rsync启动脚本2的相关文章

Shell开发rsync启动脚本

需求:实现shell脚本对rsync的start|stop|restartrsync pid所在路径:/var/run/rsyncd.pidrsync启动命令:rsync --daemonrsync进程停止命令:pkill rsync 文中通过判断rsync pid所在路径和进程状态来实现rsync的start|stop|restart 1)脚本演示 [[email protected] scripts]# cat rsync.sh #!/bin/sh #This is the launch s

企业级通过shell脚本开发MySQL启动脚本 案例

企业Shell面试题10:开发MySQL启动脚本说明MySQL启动命令为:/bin/sh mysqld_safe --pid-file=$mysqld_pid_file_path 2>&1 > /dev/null &停止命令为:mysqld_pid=`cat "$mysqld_pid_file_path"`if (kill -0 $mysqld_pid 2>/dev/null)  then    kill $mysqld_pid    sleep 2f

rsync启动脚本编写

需求:写一个rsync服务启动脚本 思路: 1.首先对脚本参数个数进行判断如果传参个数不等于1,则echo "Usage: $0 {start|restart|stop}" 2.定义函数service,通过case进行对脚本传参值的流程控制判断 3.启动服务采用命令rsync --daemon 4.停止服务采用kill -9 进程和删除rsync的PID文件 [[email protected] test]# cat /etc/init.d/rsyncd #!/bin/bash #rs

rsync启动脚本

#!/bin/bash #chkconfig: 2345 30 50 #Date:2017-6-29 #Author:xcn([email protected]) #version 1.0 PID="/var/run/rsync.pid" start_rsync(){ if [ -f $PID ]   then  echo "rsync is running" else  rsync --daemon echo "rsync is started"

rsync 启动脚本

#!/bin/bash . /etc/init.d/functions pidfile="/var/run/rsyncd.pid" start_rsync="rsync --daemon --config=/etc/rsyncd.conf" status1=$(ps -ef | egrep "rsync --daemon.*rsyncd.conf" | grep -v 'grep') function usage() { echo $"

python开发mongodb启动脚本

#!/usr/bin/env python #coding:utf-8 import os import sys def start(): os.system('/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/mongodb.conf') def stop(): os.system('/usr/local/mongodb/bin/mongod --shutdown --dbpath /data/mongodb/db') def s

Nginx启动脚本大家来找茬

今天讲到shell编程,我给大家讲解手工开发Nginx启动脚本时,写的脚本,调试发现有问题, 挺有意思的一个问题点,有2个地方有影响启动和停止的问题,有兴趣的可以研究下, 一周后公布结果! [[email protected] 03]# cat nginxd-good  #!/bin/sh RETVAL=0 path="/application/nginx" . /etc/init.d/functions start(){ if [ ! -f "$path/logs/ngin

开发rsync服务的启动脚本

开发rsync服务的启动脚本 1.查看rsync软件包是否安装: [[email protected] scripts]# rpm -qa rsync rsync-3.0.6-9.el6_4.1.x86_64 [[email protected] scripts]# touch /etc/rsyncd.conf [[email protected] scripts]# rsync --daemon [[email protected] scripts]# netstat -lntup |grep

利用shell开发rsync服务启动脚本

利用shell函数开发rsync服务启动脚本,之前的不够专业 #!/bin/bash #chkconfig: 2345  20 80                       #这两行加入kconfig #description: Saves and restores system entropy  pool source /etc/init.d/functions    #调用标准的函数库 aa() {   echo "plz one canshu"   exit 5 } bb()