Seven, Shell Script advanced programming combat seventh

First, write network service system startup scripts

   Use a case statement to develop a similar system startup script rsync services

   Code:

#!/bin/sah
. /etc/init.d/functions
pidfile="/var/run/rsyncd.pid"
start_rsync(){
if  [ -f "$pidfile" ]
  then
    echo "rsync is running"
else
   rsync --daemon
   action "rsync is started" /bin/true
fi
}
stop_rsync(){
if [ -f "$pidfile" -a -n "$pidfile" ]
 then
   kill -USR2 `cat $pidfile`
   rm -f ${pidfile}
   action "rsync is stopped" /bin/true
else
   action "rsync have already been  rstopped" /bin/false
fi
}
case "$1" in
  start)
    start_rsync
    RETVAL=$?
    ;;
  stop)
    stop_rsync
    RETVAL=$?
    ;;
  restart)
   stop_rsync
   sleep 10
   start_rsync
    RETVAL=$?
   ;;
   *)
   echo "USAGE: $0 {start|stop|restart}"
   exit 1
   ;;
esac
exit $RETVAL

 test:

 

 

Guess you like

Origin www.cnblogs.com/dangjingwei/p/11615808.html