Shell脚本学习-case语句开发rsync服务的脚本
利用case语句开发类似系统启动rsync启动服务的脚本。(可以参考系统rpcbind、nfs的脚本)。
例如:
/etc/init.d/rsyncd {start | stop | restart }
rsync --daemon
pkill rsync
[root@vm1 scripts]# cat start_rsync.sh
#!/bin/bash
#[ -f /etc/init.d/functions ] && . /etc/init.d/functions || exit 1usage() {echo "USAGE: $0 {start|stop|restart}"exit 1
}if [ $# -ne 1 ]thenusage
ficase "$1" instart)if [ `netstat -atunlp |grep 873|wc -l` -lt 2 ]thenrsync --daemonaction "rsync is :started." /bin/trueelseaction "rsync is running." /bin/falsefi;;stop)if [ `netstat -atunlp |grep 873|wc -l` -lt 2 ]thenaction "rsync is not running." /bin/falseelsepkill rsyncaction "rsync is stopped." /bin/truefi;;restart)pkill rsyncsleep 2rsync --daemon;;*)usage
esac
代码说明: