浏览代码

Format all script (Tab width:2 spaces)

lj2007331 8 年之前
父节点
当前提交
7872033b80

+ 29 - 29
init.d/Memcached-init-CentOS

@@ -17,59 +17,59 @@ DAEMON=/usr/local/memcached/bin/memcached
 
 if [ "$NETWORKING" = "no" ]
 then
-    exit 0
+  exit 0
 fi
 
 RETVAL=0
 prog="memcached"
 
 start () {
-    echo -n $"Starting $prog: "
-    # insure that /var/run/memcached has proper permissions
-    mkdir -p /var/run/memcached
-    if [ "`stat -c %U /var/run/memcached`" != "$USER" ]; then
-        chown $USER /var/run/memcached
-    fi
-    $DAEMON -d -p $PORT -u $USER  -m $CACHESIZE -c $MAXCONN -P /var/run/memcached/memcached.pid $OPTIONS
-    RETVAL=$?
-    echo
-    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/memcached
+  echo -n $"Starting $prog: "
+  # insure that /var/run/memcached has proper permissions
+  mkdir -p /var/run/memcached
+  if [ "`stat -c %U /var/run/memcached`" != "$USER" ]; then
+    chown $USER /var/run/memcached
+  fi
+  $DAEMON -d -p $PORT -u $USER  -m $CACHESIZE -c $MAXCONN -P /var/run/memcached/memcached.pid $OPTIONS
+  RETVAL=$?
+  echo
+  [ $RETVAL -eq 0 ] && touch /var/lock/subsys/memcached
 }
 stop () {
-    echo -n $"Stopping $prog: "
-    killproc memcached
-    RETVAL=$?
-    echo
-    if [ $RETVAL -eq 0 ] ; then
-        rm -f /var/lock/subsys/memcached
-        rm -f /var/run/memcached/memcached.pid
-    fi
+  echo -n $"Stopping $prog: "
+  killproc memcached
+  RETVAL=$?
+  echo
+  if [ $RETVAL -eq 0 ] ; then
+    rm -f /var/lock/subsys/memcached
+    rm -f /var/run/memcached/memcached.pid
+  fi
 }
 
 restart () {
-    stop
-    start
+  stop
+  start
 }
 
 
 # See how we were called.
 case "$1" in
-    start)
-        start
-        ;;
-    stop)
+  start)
+    start
+    ;;
+  stop)
     stop
     ;;
-    status)
+  status)
     status memcached
     ;;
-    restart|reload)
+  restart|reload)
     restart
     ;;
-    condrestart)
+  condrestart)
     [ -f /var/lock/subsys/memcached ] && restart || :
     ;;
-    *)
+  *)
     echo $"Usage: $0 {start|stop|status|restart|reload|condrestart}"
     exit 1
 esac

+ 49 - 49
init.d/Memcached-init-Ubuntu

@@ -11,75 +11,75 @@ RETVAL=0
 prog="/usr/local/memcached/bin/memcached"
 
 start_instance() {
-        echo -n $"Starting $prog ($1): "
-        start-stop-daemon --start --quiet --pidfile /var/run/memcached/memcached.$1.pid --exec $DAEMON -- -d -p $PORT -u $USER  -m $2 -c $MAXCONN -P /var/run/memcached/memcached.$1.pid $OPTIONS
-        RETVAL=$?
-        echo
-        [ $RETVAL -eq 0 ] && touch /var/lock/memcached.$1
-        PORT=`expr $PORT + 1`
+  echo -n $"Starting $prog ($1): "
+  start-stop-daemon --start --quiet --pidfile /var/run/memcached/memcached.$1.pid --exec $DAEMON -- -d -p $PORT -u $USER  -m $2 -c $MAXCONN -P /var/run/memcached/memcached.$1.pid $OPTIONS
+  RETVAL=$?
+  echo
+  [ $RETVAL -eq 0 ] && touch /var/lock/memcached.$1
+  PORT=`expr $PORT + 1`
 }
 
 stop_instance() {
-        echo -n $"Stopping $prog ($1): "
-        start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/memcached/memcached.$1.pid --exec $DAEMON
-        RETVAL=$?
-        echo
-        if [ $RETVAL -eq 0 ] ; then
-            rm -f /var/lock/memcached.$1
-            rm -f /var/run/memcached/memcached.$1.pid
-        fi
+  echo -n $"Stopping $prog ($1): "
+  start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/memcached/memcached.$1.pid --exec $DAEMON
+  RETVAL=$?
+  echo
+  if [ $RETVAL -eq 0 ] ; then
+    rm -f /var/lock/memcached.$1
+    rm -f /var/run/memcached/memcached.$1.pid
+  fi
 }
 start () {
-        # insure that /var/run/memcached has proper permissions
-        mkdir -p /var/run/memcached
-        if [ "`stat -c %U /var/run/memcached`" != "$USER" ]; then
-                chown $USER /var/run/memcached
-        fi
+  # insure that /var/run/memcached has proper permissions
+  mkdir -p /var/run/memcached
+  if [ "`stat -c %U /var/run/memcached`" != "$USER" ]; then
+    chown $USER /var/run/memcached
+  fi
 
-        start_instance default 256;
-        #start_instance block 16;
-        #start_instance content 128;
-        #start_instance filter 128;
-        #start_instance form 32;
-        #start_instance menu 16;
-        #start_instance page 8;
-        #start_instance update 8;
-        #start_instance views 8;
+  start_instance default 256;
+  #start_instance block 16;
+  #start_instance content 128;
+  #start_instance filter 128;
+  #start_instance form 32;
+  #start_instance menu 16;
+  #start_instance page 8;
+  #start_instance update 8;
+  #start_instance views 8;
 }
 stop () {
-        stop_instance default;
-        #stop_instance block;
-        #stop_instance content;
-        #stop_instance filter;
-        #stop_instance form;
-        #stop_instance menu;
-        #stop_instance page;
-        #stop_instance update;
-        #stop_instance views;
+  stop_instance default;
+  #stop_instance block;
+  #stop_instance content;
+  #stop_instance filter;
+  #stop_instance form;
+  #stop_instance menu;
+  #stop_instance page;
+  #stop_instance update;
+  #stop_instance views;
 }
 
 restart () {
-        stop
-        start
+  stop
+  start
 }
 
 # See how we were called.
 case "$1" in
   start)
-        start
-        ;;
+    start
+    ;;
   stop)
-        stop
-        ;;
+    stop
+    ;;
   status)
-        status memcached
-        ;;
+    status memcached
+    ;;
   restart|reload|force-reload)
-        restart
-        ;;
+    restart
+    ;;
   *)
-        echo $"Usage: $0 {start|stop|status|restart|reload|force-reload}"
-        exit 1
+    echo $"Usage: $0 {start|stop|status|restart|reload|force-reload}"
+    exit 1
 esac
 
 exit $?

+ 69 - 69
init.d/Nginx-init-CentOS

@@ -28,61 +28,61 @@ NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
 lockfile=/var/lock/subsys/nginx
 
 make_dirs() {
-   # make required directories
-   user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
-   if [ -z "`grep $user /etc/passwd`" ]; then
-       useradd -M -s /bin/nologin $user
-   fi
-   options=`$nginx -V 2>&1 | grep 'configure arguments:'`
-   for opt in $options; do
-       if [ `echo $opt | grep '.*-temp-path'` ]; then
-           value=`echo $opt | cut -d "=" -f 2`
-           if [ ! -d "$value" ]; then
-               # echo "creating" $value
-               mkdir -p $value && chown -R $user $value
-           fi
-       fi
-   done
+  # make required directories
+  user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
+  if [ -z "`grep $user /etc/passwd`" ]; then
+    useradd -M -s /bin/nologin $user
+  fi
+  options=`$nginx -V 2>&1 | grep 'configure arguments:'`
+  for opt in $options; do
+    if [ `echo $opt | grep '.*-temp-path'` ]; then
+      value=`echo $opt | cut -d "=" -f 2`
+      if [ ! -d "$value" ]; then
+        # echo "creating" $value
+        mkdir -p $value && chown -R $user $value
+      fi
+    fi
+  done
 }
 
 start() {
-    [ -x $nginx ] || exit 5
-    [ -f $NGINX_CONF_FILE ] || exit 6
-    make_dirs
-    echo -n $"Starting $prog: "
-    daemon $nginx -c $NGINX_CONF_FILE
-    retval=$?
-    echo
-    [ $retval -eq 0 ] && touch $lockfile
-    return $retval
+  [ -x $nginx ] || exit 5
+  [ -f $NGINX_CONF_FILE ] || exit 6
+  make_dirs
+  echo -n $"Starting $prog: "
+  daemon $nginx -c $NGINX_CONF_FILE
+  retval=$?
+  echo
+  [ $retval -eq 0 ] && touch $lockfile
+  return $retval
 }
 
 stop() {
-    echo -n $"Stopping $prog: "
-    killproc $prog -QUIT
-    retval=$?
-    echo
-    [ $retval -eq 0 ] && rm -f $lockfile
-    return $retval
+  echo -n $"Stopping $prog: "
+  killproc $prog -QUIT
+  retval=$?
+  echo
+  [ $retval -eq 0 ] && rm -f $lockfile
+  return $retval
 }
 
 restart() {
-    configtest || return $?
-    stop
-    sleep 3
-    start
+  configtest || return $?
+  stop
+  sleep 3
+  start
 }
 
 reload() {
-    configtest || return $?
-    echo -n $"Reloading $prog: "
-    killproc $nginx -HUP
-    RETVAL=$?
-    echo
+  configtest || return $?
+  echo -n $"Reloading $prog: "
+  killproc $nginx -HUP
+  RETVAL=$?
+  echo
 }
 
 force_reload() {
-    restart
+  restart
 }
 
 configtest() {
@@ -90,39 +90,39 @@ configtest() {
 }
 
 rh_status() {
-    status $prog
+  status $prog
 }
 
 rh_status_q() {
-    rh_status >/dev/null 2>&1
+  rh_status >/dev/null 2>&1
 }
 
 case "$1" in
-    start)
-        rh_status_q && exit 0
-        $1
-        ;;
-    stop)
-        rh_status_q || exit 0
-        $1
-        ;;
-    restart|configtest)
-        $1
-        ;;
-    reload)
-        rh_status_q || exit 7
-        $1
-        ;;
-    force-reload)
-        force_reload
-        ;;
-    status)
-        rh_status
-        ;;
-    condrestart|try-restart)
-        rh_status_q || exit 0
-            ;;
-    *)
-        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
-        exit 2
+  start)
+    rh_status_q && exit 0
+    $1
+    ;;
+  stop)
+    rh_status_q || exit 0
+    $1
+    ;;
+  restart|configtest)
+    $1
+    ;;
+  reload)
+    rh_status_q || exit 7
+    $1
+    ;;
+  force-reload)
+    force_reload
+    ;;
+  status)
+    rh_status
+    ;;
+  condrestart|try-restart)
+    rh_status_q || exit 0
+    ;;
+  *)
+    echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
+    exit 2
 esac

+ 162 - 164
init.d/Nginx-init-Ubuntu

@@ -68,7 +68,7 @@ test -x $DAEMON || exit 0
 
 # Include nginx defaults if available
 if [ -f /etc/default/nginx ] ; then
-        . /etc/default/nginx
+  . /etc/default/nginx
 fi
 
 #set exit condition
@@ -80,233 +80,231 @@ fi
 
 setFilePerms(){
 
-        if [ -f $PIDSPATH/$PIDFILE ]; then
-                chmod 400 $PIDSPATH/$PIDFILE
-        fi
+  if [ -f $PIDSPATH/$PIDFILE ]; then
+    chmod 400 $PIDSPATH/$PIDFILE
+  fi
 }
 
 configtest() {
-    $DAEMON -t -c $NGINX_CONF_FILE
+  $DAEMON -t -c $NGINX_CONF_FILE
 }
 
 getPSCount() {
-    return `pgrep -f $PS | wc -l`
+  return `pgrep -f $PS | wc -l`
 }
 
 isRunning() {
-        if [ $1 ]; then
-                pidof_daemon $1
-                PID=$?
-
-                if [ $PID -gt 0 ]; then
-                        return 1
-                else
-                        return 0
-                fi
-        else
-                pidof_daemon
-                PID=$?
-
-                if [ $PID -gt 0 ]; then
-                        return 1
-                else
-                        return 0
-                fi
-        fi
+  if [ $1 ]; then
+    pidof_daemon $1
+    PID=$?
+
+    if [ $PID -gt 0 ]; then
+      return 1
+    else
+      return 0
+    fi
+  else
+    pidof_daemon
+    PID=$?
+
+    if [ $PID -gt 0 ]; then
+      return 1
+    else
+      return 0
+    fi
+  fi
 }
 
 #courtesy of php-fpm
 wait_for_pid () {
-        try=0
-
-        while test $try -lt 35 ; do
-
-                case "$1" in
-                        'created')
-                        if [ -f "$2" ] ; then
-                                try=''
-                                break
-                        fi
-                        ;;
-
-                        'removed')
-                        if [ ! -f "$2" ] ; then
-                                try=''
-                                break
-                        fi
-                        ;;
-                esac
-
-                #echo -n .
-                try=`expr $try + 1`
-                sleep 1
-        done
+  try=0
+
+  while test $try -lt 35 ; do
+
+    case "$1" in
+      'created')
+      if [ -f "$2" ] ; then
+        try=''
+        break
+      fi
+      ;;
+
+      'removed')
+      if [ ! -f "$2" ] ; then
+        try=''
+        break
+      fi
+      ;;
+    esac
+
+    #echo -n .
+    try=`expr $try + 1`
+    sleep 1
+  done
 }
 
 status(){
-    isRunning
-    isAlive=$?
-
-    if [ "${isAlive}" -eq $TRUE ]; then
-                echo "$PIDNAME found running with processes:  `pidof $PS`"
-        else
-                echo "$PIDNAME is NOT running."
-        fi
-
-
+  isRunning
+  isAlive=$?
+
+  if [ "${isAlive}" -eq $TRUE ]; then
+    echo "$PIDNAME found running with processes:  `pidof $PS`"
+  else
+    echo "$PIDNAME is NOT running."
+  fi
 }
 
 removePIDFile(){
-    if [ $1 ]; then
-                if [ -f $1 ]; then
-                    rm -f $1
-            fi
-        else
-        #Do default removal
-        if [ -f $PIDSPATH/$PIDFILE ]; then
-                    rm -f $PIDSPATH/$PIDFILE
-            fi
-        fi
+  if [ $1 ]; then
+    if [ -f $1 ]; then
+      rm -f $1
+    fi
+  else
+    #Do default removal
+    if [ -f $PIDSPATH/$PIDFILE ]; then
+      rm -f $PIDSPATH/$PIDFILE
+    fi
+  fi
 }
 
 start() {
-        log_daemon_msg "Starting $DESCRIPTION"
+  log_daemon_msg "Starting $DESCRIPTION"
 
-    isRunning
-    isAlive=$?
+  isRunning
+  isAlive=$?
 
-        if [ "${isAlive}" -eq $TRUE ]; then
-                log_end_msg $SCRIPT_ERROR
-        else
-                start-stop-daemon --start --quiet --chuid $RUNAS --pidfile $PIDSPATH/$PIDFILE --exec $DAEMON \
-                -- -c $NGINX_CONF_FILE
-                setFilePerms
-                log_end_msg $SCRIPT_OK
-        fi
+  if [ "${isAlive}" -eq $TRUE ]; then
+    log_end_msg $SCRIPT_ERROR
+  else
+    start-stop-daemon --start --quiet --chuid $RUNAS --pidfile $PIDSPATH/$PIDFILE --exec $DAEMON \
+    -- -c $NGINX_CONF_FILE
+    setFilePerms
+    log_end_msg $SCRIPT_OK
+  fi
 }
 
 stop() {
-    log_daemon_msg "Stopping $DESCRIPTION"
+  log_daemon_msg "Stopping $DESCRIPTION"
 
-    isRunning
-    isAlive=$?
-        if [ "${isAlive}" -eq $TRUE ]; then
-                start-stop-daemon --stop --quiet --pidfile $PIDSPATH/$PIDFILE
+  isRunning
+  isAlive=$?
+  if [ "${isAlive}" -eq $TRUE ]; then
+    start-stop-daemon --stop --quiet --pidfile $PIDSPATH/$PIDFILE
 
-        wait_for_pid 'removed' $PIDSPATH/$PIDFILE
+    wait_for_pid 'removed' $PIDSPATH/$PIDFILE
 
-                if [ -n "$try" ] ; then
-                        log_end_msg $SCRIPT_ERROR
-                else
-                        removePIDFile
-                    log_end_msg $SCRIPT_OK
-                fi
+    if [ -n "$try" ] ; then
+      log_end_msg $SCRIPT_ERROR
+    else
+      removePIDFile
+      log_end_msg $SCRIPT_OK
+    fi
 
-        else
-                log_end_msg $SCRIPT_ERROR
-        fi
+  else
+    log_end_msg $SCRIPT_ERROR
+  fi
 }
 
 reload() {
-    configtest || return $?
+  configtest || return $?
 
-    log_daemon_msg "Reloading (via HUP) $DESCRIPTION"
+  log_daemon_msg "Reloading (via HUP) $DESCRIPTION"
 
-        isRunning
-        if [ $? -eq $TRUE ]; then
-        `killall -HUP $PS` #to be safe
+  isRunning
+  if [ $? -eq $TRUE ]; then
+    `killall -HUP $PS` #to be safe
 
-                log_end_msg $SCRIPT_OK
-        else
-                log_end_msg $SCRIPT_ERROR
-        fi
+    log_end_msg $SCRIPT_OK
+  else
+    log_end_msg $SCRIPT_ERROR
+  fi
 }
 
 quietupgrade() {
-    log_daemon_msg "Peforming Quiet Upgrade $DESCRIPTION"
-
-        isRunning
-        isAlive=$?
-        if [ "${isAlive}" -eq $TRUE ]; then
-        kill -USR2 `cat $PIDSPATH/$PIDFILE`
-        kill -WINCH `cat $PIDSPATH/$PIDFILE.oldbin`
-
-        isRunning
-        isAlive=$?
-        if [ "${isAlive}" -eq $TRUE ]; then
-            kill -QUIT `cat $PIDSPATH/$PIDFILE.oldbin`
-            wait_for_pid 'removed' $PIDSPATH/$PIDFILE.oldbin
-                        removePIDFile $PIDSPATH/$PIDFILE.oldbin
-
-            log_end_msg $SCRIPT_OK
-        else
-            log_end_msg $SCRIPT_ERROR
-
-            log_daemon_msg "ERROR! Reverting back to original $DESCRIPTION"
-
-            kill -HUP `cat $PIDSPATH/$PIDFILE`
-            kill -TERM `cat $PIDSPATH/$PIDFILE.oldbin`
-            kill -QUIT `cat $PIDSPATH/$PIDFILE.oldbin`
-
-            wait_for_pid 'removed' $PIDSPATH/$PIDFILE.oldbin
-                        removePIDFile $PIDSPATH/$PIDFILE.oldbin
-
-            log_end_msg $SCRIPT_ok
-        fi
-        else
-                log_end_msg $SCRIPT_ERROR
-        fi
+  log_daemon_msg "Peforming Quiet Upgrade $DESCRIPTION"
+
+  isRunning
+  isAlive=$?
+  if [ "${isAlive}" -eq $TRUE ]; then
+    kill -USR2 `cat $PIDSPATH/$PIDFILE`
+    kill -WINCH `cat $PIDSPATH/$PIDFILE.oldbin`
+
+    isRunning
+    isAlive=$?
+    if [ "${isAlive}" -eq $TRUE ]; then
+      kill -QUIT `cat $PIDSPATH/$PIDFILE.oldbin`
+      wait_for_pid 'removed' $PIDSPATH/$PIDFILE.oldbin
+      removePIDFile $PIDSPATH/$PIDFILE.oldbin
+
+      log_end_msg $SCRIPT_OK
+    else
+      log_end_msg $SCRIPT_ERROR
+
+      log_daemon_msg "ERROR! Reverting back to original $DESCRIPTION"
+
+      kill -HUP `cat $PIDSPATH/$PIDFILE`
+      kill -TERM `cat $PIDSPATH/$PIDFILE.oldbin`
+      kill -QUIT `cat $PIDSPATH/$PIDFILE.oldbin`
+
+      wait_for_pid 'removed' $PIDSPATH/$PIDFILE.oldbin
+      removePIDFile $PIDSPATH/$PIDFILE.oldbin
+
+      log_end_msg $SCRIPT_ok
+    fi
+  else
+    log_end_msg $SCRIPT_ERROR
+  fi
 }
 
 terminate() {
-        log_daemon_msg "Force terminating (via KILL) $DESCRIPTION"
+  log_daemon_msg "Force terminating (via KILL) $DESCRIPTION"
 
-    PIDS=`pidof $PS` || true
+  PIDS=`pidof $PS` || true
 
-    [ -e $PIDSPATH/$PIDFILE ] && PIDS2=`cat $PIDSPATH/$PIDFILE`
+  [ -e $PIDSPATH/$PIDFILE ] && PIDS2=`cat $PIDSPATH/$PIDFILE`
 
-    for i in $PIDS; do
-        if [ "$i" = "$PIDS2" ]; then
-                kill $i
-                        wait_for_pid 'removed' $PIDSPATH/$PIDFILE
-            removePIDFile
-        fi
-    done
+  for i in $PIDS; do
+    if [ "$i" = "$PIDS2" ]; then
+      kill $i
+      wait_for_pid 'removed' $PIDSPATH/$PIDFILE
+      removePIDFile
+    fi
+  done
 
-    log_end_msg $SCRIPT_OK
+  log_end_msg $SCRIPT_OK
 }
 
 destroy() {
-    log_daemon_msg "Force terminating and may include self (via KILLALL) $DESCRIPTION"
-    killall $PS -q >> /dev/null 2>&1
-    log_end_msg $SCRIPT_OK
+  log_daemon_msg "Force terminating and may include self (via KILLALL) $DESCRIPTION"
+  killall $PS -q >> /dev/null 2>&1
+  log_end_msg $SCRIPT_OK
 }
 
 pidof_daemon() {
-    PIDS=`pidof $PS` || true
+  PIDS=`pidof $PS` || true
 
-    [ -e $PIDSPATH/$PIDFILE ] && PIDS2=`cat $PIDSPATH/$PIDFILE`
+  [ -e $PIDSPATH/$PIDFILE ] && PIDS2=`cat $PIDSPATH/$PIDFILE`
 
-    for i in $PIDS; do
-        if [ "$i" = "$PIDS2" ]; then
-            return 1
-        fi
-    done
-    return 0
+  for i in $PIDS; do
+    if [ "$i" = "$PIDS2" ]; then
+      return 1
+    fi
+  done
+  return 0
 }
 
 case "$1" in
   start)
     start
-        ;;
+    ;;
   stop)
     stop
-        ;;
+    ;;
   restart|force-reload)
     stop
     sleep 3
     start
-        ;;
+    ;;
   reload)
     $1
     ;;
@@ -314,8 +312,8 @@ case "$1" in
     status
     ;;
   configtest)
-        $1
-        ;;
+    $1
+    ;;
   quietupgrade)
     $1
     ;;

+ 38 - 38
init.d/Pureftpd-init

@@ -23,49 +23,49 @@ pure_config=/usr/local/pureftpd/etc/pure-ftpd.conf
 
 
 start() {
-	echo -n $"Starting $prog: "
-	$fullpath $pure_config --daemonize
-	RETVAL=$?
-	[ $RETVAL = 0 ] && touch /var/lock/subsys/$prog
-	echo
+  echo -n $"Starting $prog: "
+  $fullpath $pure_config --daemonize
+  RETVAL=$?
+  [ $RETVAL = 0 ] && touch /var/lock/subsys/$prog
+  echo
 }
 stop() {
-	echo -n $"Stopping $prog: "
-	kill $(cat /var/run/pure-ftpd.pid)
-	RETVAL=$?
-	[ $RETVAL = 0 ] && rm -f /var/lock/subsys/$prog
-	echo
+  echo -n $"Stopping $prog: "
+  kill $(cat /var/run/pure-ftpd.pid)
+  RETVAL=$?
+  [ $RETVAL = 0 ] && rm -f /var/lock/subsys/$prog
+  echo
 }
 
 # See how we were called.
 case "$1" in
-	start)
-		start
-		;;
-	stop)
-		stop
-		;;
-	restart)
-		stop
-		start
-		;;
-	condrestart)
-		if [ -f /var/lock/subsys/$prog ] ; then
-			stop
-			# avoid race
-			sleep 3
-			start
-		fi
-		;;
-	status)
-		status $prog
-		RETVAL=$?
-		if [ -f $pureftpwho ] && [ $RETVAL -eq 0 ] ; then
-			$pureftpwho
-		fi
-		;;
-	*)
-		echo $"Usage: $prog {start|stop|restart|condrestart|status}"
-		RETVAL=1
+  start)
+    start
+    ;;
+  stop)
+    stop
+    ;;
+  restart)
+    stop
+    start
+    ;;
+  condrestart)
+    if [ -f /var/lock/subsys/$prog ] ; then
+      stop
+      # avoid race
+      sleep 3
+      start
+    fi
+    ;;
+  status)
+    status $prog
+    RETVAL=$?
+    if [ -f $pureftpwho ] && [ $RETVAL -eq 0 ] ; then
+      $pureftpwho
+    fi
+    ;;
+  *)
+    echo $"Usage: $prog {start|stop|restart|condrestart|status}"
+    RETVAL=1
 esac
 exit $RETVAL

+ 4 - 4
init.d/Redis-server-init

@@ -31,18 +31,18 @@ case "$1" in
     chown redis:redis $PIDFILE
     if start-stop-daemon --start --quiet --pidfile $PIDFILE --chuid redis:redis --exec $DAEMON -- $DAEMON_ARGS
     then
-        echo "$NAME."
+      echo "$NAME."
     else
-        echo "failed"
+      echo "failed"
     fi
     ;;
   stop)
     echo -n "Stopping $DESC: "
     if start-stop-daemon --stop --retry 10 --quiet --oknodo --pidfile $PIDFILE --exec $DAEMON
     then
-        echo "$NAME."
+      echo "$NAME."
     else
-        echo "failed"
+      echo "failed"
     fi
     rm -f $PIDFILE
     ;;

+ 49 - 49
init.d/Shadowsocks-libev-init

@@ -39,9 +39,9 @@ mkdir /var/run/$NAME 2>/dev/null || true
 
 # Check the configuration file exists.
 #
-if [ ! -f $CONF ] ; then
-echo "The configuration file cannot be found!"
-exit 0
+if [ ! -f $CONF ]; then
+  echo "The configuration file cannot be found!"
+  exit 0
 fi
 
 # Path to the lock file.
@@ -63,62 +63,62 @@ RETVAL=0
 # Start shadowsocks as daemon.
 #
 start() {
-if [ -f $LOCK_FILE ]; then
-echo "$NAME is already running!"
-exit 0
-else
-echo -n $"Starting ${NAME}: "
-#daemon --check $DAEMON --user $USER "$DAEMON -f $PID -c $CONF > /dev/null"
-daemon $DAEMON -u -c $CONF -f $PID
-fi
-
-RETVAL=$?
-[ $RETVAL -eq 0 ] && success
-echo
-[ $RETVAL -eq 0 ] && touch $LOCK_FILE
-return $RETVAL
+  if [ -f $LOCK_FILE ]; then
+    echo "$NAME is already running!"
+    exit 0
+  else
+    echo -n $"Starting ${NAME}: "
+    #daemon --check $DAEMON --user $USER "$DAEMON -f $PID -c $CONF > /dev/null"
+    daemon $DAEMON -u -c $CONF -f $PID
+  fi
+
+  RETVAL=$?
+  [ $RETVAL -eq 0 ] && success
+  echo
+  [ $RETVAL -eq 0 ] && touch $LOCK_FILE
+  return $RETVAL
 }
 
 
 # Stop shadowsocks.
 #
 stop() {
-echo -n $"Shutting down ${NAME}: "
-killproc -p ${PID}
-RETVAL=$?
-[ $RETVAL -eq 0 ]
-rm -f $LOCK_FILE
-rm -f ${PID}
-echo
-return $RETVAL
+  echo -n $"Shutting down ${NAME}: "
+  killproc -p ${PID}
+  RETVAL=$?
+  [ $RETVAL -eq 0 ]
+  rm -f $LOCK_FILE
+  rm -f ${PID}
+  echo
+  return $RETVAL
 }
 
 # See how we were called.
 case "$1" in
-start)
-start
-;;
-stop)
-stop
-;;
-restart)
-stop
-start
-;;
-condrestart)
-if [ -f $LOCK_FILE ]; then
-stop
-start
-RETVAL=$?
-fi
-;;
-status)
-status $DAEMON
-RETVAL=$?
-;;
-*)
-echo $"Usage: $0 {start|stop|restart|condrestart|status}"
-RETVAL=1
+  start)
+    start
+    ;;
+  stop)
+    stop
+    ;;
+  restart)
+    stop
+    start
+    ;;
+  condrestart)
+    if [ -f $LOCK_FILE ]; then
+    stop
+    start
+    RETVAL=$?
+    fi
+    ;;
+  status)
+    status $DAEMON
+    RETVAL=$?
+    ;;
+  *)
+    echo $"Usage: $0 {start|stop|restart|condrestart|status}"
+    RETVAL=1
 esac
 
 exit $RETVAL

+ 17 - 17
init.d/Shadowsocks-python-init

@@ -20,7 +20,7 @@ Shadowsocks_pid(){
 
 start() {
   pid=$(Shadowsocks_pid)
-  if [ -n "$pid" ];then
+  if [ -n "$pid" ]; then
     echo -e "\e[00;31mShadowsocks is already running (pid: $pid)\e[00m"
   else
     $Shadowsocks_bin -c $Shadowsocks_conf -d start
@@ -37,7 +37,7 @@ start() {
 
 status(){
   pid=$(Shadowsocks_pid)
-  if [ -n "$pid" ];then
+  if [ -n "$pid" ]; then
     echo -e "\e[00;32mShadowsocks is running with pid: $pid\e[00m"
   else
     echo -e "\e[00;31mShadowsocks is not running\e[00m"
@@ -46,7 +46,7 @@ status(){
 
 stop(){
   pid=$(Shadowsocks_pid)
-  if [ -n "$pid" ];then
+  if [ -n "$pid" ]; then
     echo -e "\e[00;31mStoping Shadowsocks\e[00m"
     $Shadowsocks_bin -c $Shadowsocks_conf -d stop
     let kwait=$SHUTDOWN_WAIT
@@ -58,7 +58,7 @@ stop(){
       let count=$count+1;
     done
 
-    if [ $count -gt $kwait ];then
+    if [ $count -gt $kwait ]; then
       echo -n -e "\n\e[00;31mkilling processes which didn't stop after $SHUTDOWN_WAIT seconds\e[00m"
       kill -9 $pid
     fi
@@ -71,20 +71,20 @@ stop(){
 
 case $1 in
   start)
-          start
-        ;;
-        stop)
-          stop
-        ;;
-        restart)
-          stop
-          start
-        ;;
-        status)
+    start
+    ;;
+  stop)
+    stop
+    ;;
+  restart)
+    stop
+    start
+    ;;
+  status)
     status
-        ;;
-        *)
+    ;;
+  *)
     echo -e $Shadowsocks_USAGE
-        ;;
+    ;;
 esac
 exit 0

+ 79 - 82
init.d/Supervisor-init-CentOS

@@ -43,111 +43,108 @@ ulimit -n 96000
 RETVAL=0
 
 
-running_pid()
-{
-    # Check if a given process pid's cmdline matches a given name
-    pid=$1
-    name=$2
-    [ -z "$pid" ] && return 1
-    [ ! -d /proc/$pid ] && return 1
-    (cat /proc/$pid/cmdline | tr "\000" "\n"|grep -q $name) || return 1
-    return 0
+running_pid() {
+  # Check if a given process pid's cmdline matches a given name
+  pid=$1
+  name=$2
+  [ -z "$pid" ] && return 1
+  [ ! -d /proc/$pid ] && return 1
+  (cat /proc/$pid/cmdline | tr "\000" "\n"|grep -q $name) || return 1
+  return 0
 }
 
-running()
-{
+running() {
 # Check if the process is running looking at /proc
 # (works for all users)
 
-    # No pidfile, probably no daemon present
-    [ ! -f "$PIDFILE" ] && return 1
-    # Obtain the pid and check it against the binary name
-    pid=`cat $PIDFILE`
-    running_pid $pid $SUPERVISORD || return 1
-    return 0
+  # No pidfile, probably no daemon present
+  [ ! -f "$PIDFILE" ] && return 1
+  # Obtain the pid and check it against the binary name
+  pid=`cat $PIDFILE`
+  running_pid $pid $SUPERVISORD || return 1
+  return 0
 }
 
 start() {
-        echo "Starting supervisord: "
+  echo "Starting supervisord: "
 
-        if [ -e $PIDFILE ]; then
-        echo "ALREADY STARTED"
-        return 1
-    fi
+  if [ -e $PIDFILE ]; then
+    echo "ALREADY STARTED"
+    return 1
+  fi
 
-    # start supervisord with options from sysconfig (stuff like -c)
-        $SUPERVISORD $OPTIONS
+  # start supervisord with options from sysconfig (stuff like -c)
+  $SUPERVISORD $OPTIONS
 
-    # show initial startup status
-    $SUPERVISORCTL $OPTIONS status
+  # show initial startup status
+  $SUPERVISORCTL $OPTIONS status
 
-    # only create the subsyslock if we created the PIDFILE
-        [ -e $PIDFILE ] && touch $LOCKFILE
+  # only create the subsyslock if we created the PIDFILE
+  [ -e $PIDFILE ] && touch $LOCKFILE
 }
 
 stop() {
-        echo -n "Stopping supervisord: "
-        $SUPERVISORCTL $OPTIONS shutdown
-    if [ -n "$WAIT_FOR_SUBPROCESSES" ]; then
-            echo "Waiting roughly 60 seconds for $PIDFILE to be removed after child processes exit"
-            for sleep in  2 2 2 2 4 4 4 4 8 8 8 8 last; do
-                if [ ! -e $PIDFILE ] ; then
-                    echo "Supervisord exited as expected in under $total_sleep seconds"
-                    break
-                else
-                    if [[ $sleep -eq "last" ]] ; then
-                        echo "Supervisord still working on shutting down. We've waited roughly 60 seconds, we'll let it do its thing from here"
-                        return 1
-                    else
-                        sleep $sleep
-                        total_sleep=$(( $total_sleep + $sleep ))
-                    fi
-
-                fi
-            done
+  echo -n "Stopping supervisord: "
+  $SUPERVISORCTL $OPTIONS shutdown
+  if [ -n "$WAIT_FOR_SUBPROCESSES" ]; then
+    echo "Waiting roughly 60 seconds for $PIDFILE to be removed after child processes exit"
+    for sleep in  2 2 2 2 4 4 4 4 8 8 8 8 last; do
+      if [ ! -e $PIDFILE ] ; then
+        echo "Supervisord exited as expected in under $total_sleep seconds"
+        break
+      else
+        if [[ $sleep -eq "last" ]] ; then
+          echo "Supervisord still working on shutting down. We've waited roughly 60 seconds, we'll let it do its thing from here"
+          return 1
+        else
+          sleep $sleep
+          total_sleep=$(( $total_sleep + $sleep ))
         fi
+      fi
+    done
+  fi
 
-        # always remove the subsys. We might have waited a while, but just remove it at this point.
-        rm -f $LOCKFILE
+  # always remove the subsys. We might have waited a while, but just remove it at this point.
+  rm -f $LOCKFILE
 }
 
 restart() {
-        stop
-        start
+  stop
+  start
 }
 
 case "$1" in
-    start)
-        start
-        RETVAL=$?
-        ;;
-    stop)
-        stop
-        RETVAL=$?
-        ;;
-    restart|force-reload)
-        restart
-        RETVAL=$?
-        ;;
-    reload)
-        $SUPERVISORCTL $OPTIONS reload
-        RETVAL=$?
-        ;;
-    condrestart)
-        [ -f $LOCKFILE ] && restart
-        RETVAL=$?
-        ;;
-    status)
-        $SUPERVISORCTL $OPTIONS status
-        if running ; then
-            RETVAL=0
-        else
-            RETVAL=1
-        fi
-        ;;
-    *)
-        echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
-        exit 1
+  start)
+    start
+    RETVAL=$?
+    ;;
+  stop)
+    stop
+    RETVAL=$?
+    ;;
+  restart|force-reload)
+    restart
+    RETVAL=$?
+    ;;
+  reload)
+    $SUPERVISORCTL $OPTIONS reload
+    RETVAL=$?
+    ;;
+  condrestart)
+    [ -f $LOCKFILE ] && restart
+    RETVAL=$?
+    ;;
+  status)
+    $SUPERVISORCTL $OPTIONS status
+    if running ; then
+      RETVAL=0
+    else
+      RETVAL=1
+    fi
+    ;;
+  *)
+    echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
+    exit 1
 esac
 
 exit $RETVAL

+ 23 - 27
init.d/Tomcat-init

@@ -22,16 +22,16 @@ TOMCAT_USAGE="Usage: $0 {\e[00;32mstart\e[00m|\e[00;31mstop\e[00m|\e[00;32mstatu
 SHUTDOWN_WAIT=20
 
 tomcat_pid() {
-        echo `ps -ef | grep $CATALINA_HOME/ | grep -v grep | tr -s " "|cut -d" " -f2`
+  echo `ps -ef | grep $CATALINA_HOME/ | grep -v grep | tr -s " "|cut -d" " -f2`
 }
 
 start() {
   pid=$(tomcat_pid)
-  if [ -n "$pid" ];then
+  if [ -n "$pid" ]; then
     echo -e "\e[00;31mTomcat is already running (pid: $pid)\e[00m"
   else
     echo -e "\e[00;32mStarting tomcat\e[00m"
-    if [ `user_exists $TOMCAT_USER` = "1" ];then
+    if [ `user_exists $TOMCAT_USER` = "1" ]; then
       su $TOMCAT_USER -c $CATALINA_HOME/bin/startup.sh
     else
       $CATALINA_HOME/bin/startup.sh
@@ -41,9 +41,9 @@ start() {
   return 0
 }
 
-status(){
+status() {
   pid=$(tomcat_pid)
-  if [ -n "$pid" ];then
+  if [ -n "$pid" ]; then
     echo -e "\e[00;32mTomcat is running with pid: $pid\e[00m"
   else
     echo -e "\e[00;31mTomcat is not running\e[00m"
@@ -52,9 +52,9 @@ status(){
 
 stop() {
   pid=$(tomcat_pid)
-  if [ -n "$pid" ];then
+  if [ -n "$pid" ]; then
     echo -e "\e[00;31mStoping Tomcat\e[00m"
-        $CATALINA_HOME/bin/shutdown.sh
+    $CATALINA_HOME/bin/shutdown.sh
 
     let kwait=$SHUTDOWN_WAIT
     count=0;
@@ -65,7 +65,7 @@ stop() {
       let count=$count+1;
     done
 
-    if [ $count -gt $kwait ];then
+    if [ $count -gt $kwait ]; then
       echo -n -e "\n\e[00;31mkilling processes which didn't stop after $SHUTDOWN_WAIT seconds\e[00m"
       kill -9 $pid
     fi
@@ -76,7 +76,7 @@ stop() {
   return 0
 }
 
-user_exists(){
+user_exists() {
   if id -u $1 >/dev/null 2>&1; then
     echo "1"
   else
@@ -85,25 +85,21 @@ user_exists(){
 }
 
 case $1 in
-        start)
-          start
-        ;;
-
-        stop)
-          stop
-        ;;
-
-        restart)
-          stop
-          start
-        ;;
-
-        status)
+  start)
+    start
+    ;;
+  stop)
+    stop
+    ;;
+  restart)
+    stop
+    start
+    ;;
+  status)
     status
-        ;;
-
-        *)
+    ;;
+  *)
     echo -e $TOMCAT_USAGE
-        ;;
+    ;;
 esac
 exit 0

+ 3 - 3
tools/ckssh.py

@@ -6,8 +6,8 @@ import socket,sys
 sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 sk.settimeout(1)
 try:
-    sk.connect((sys.argv[1],int(sys.argv[2])))
-    print 'ok'
+  sk.connect((sys.argv[1],int(sys.argv[2])))
+  print 'ok'
 except Exception:
-    print 'no'
+  print 'no'
 sk.close()

+ 9 - 9
tools/db_bk.sh

@@ -23,18 +23,18 @@ DB_tmp=`$db_install_dir/bin/mysql -uroot -p$dbrootpwd -e "show databases\G" | gr
 [ -z "$DB_tmp" ] && { echo "[$DBname] not exist" >> $LogFile ;  exit 1 ; }
 
 if [ -n "`ls $OldFile 2>/dev/null`" ];then
-    /bin/rm -f $OldFile
-    echo "[$OldFile] Delete Old File Success" >> $LogFile
+  /bin/rm -f $OldFile
+  echo "[$OldFile] Delete Old File Success" >> $LogFile
 else
-    echo "[$OldFile] Delete Old Backup File" >> $LogFile
+  echo "[$OldFile] Delete Old Backup File" >> $LogFile
 fi
 
 if [ -e "$NewFile" ];then
-    echo "[$NewFile] The Backup File is exists, Can't Backup" >> $LogFile
+  echo "[$NewFile] The Backup File is exists, Can't Backup" >> $LogFile
 else
-    $db_install_dir/bin/mysqldump -uroot -p$dbrootpwd --databases $DBname > $DumpFile
-    cd $backup_dir
-    tar czf $NewFile ${DumpFile##*/} >> $LogFile 2>&1
-    echo "[$NewFile] Backup success ">> $LogFile
-    /bin/rm -f $DumpFile
+  $db_install_dir/bin/mysqldump -uroot -p$dbrootpwd --databases $DBname > $DumpFile
+  cd $backup_dir
+  tar czf $NewFile ${DumpFile##*/} >> $LogFile 2>&1
+  echo "[$NewFile] Backup success ">> $LogFile
+  /bin/rm -f $DumpFile
 fi

+ 121 - 124
tools/mabs.sh

@@ -4,45 +4,42 @@
 
 ######################  proc defination  ########################
 # ignore rule
-ignore_init()
-{
-    # ignore password
-    array_ignore_pwd_length=0
-    if [ -f ./ignore_pwd ]; then
-        while read IGNORE_PWD
-        do
-            array_ignore_pwd[$array_ignore_pwd_length]=$IGNORE_PWD
-            let array_ignore_pwd_length=$array_ignore_pwd_length+1
-        done < ./ignore_pwd
-    fi
-
-    # ignore ip address
-    array_ignore_ip_length=0
-    if [ -f ./ignore_ip ]; then
-        while read IGNORE_IP
-        do
-            array_ignore_ip[$array_ignore_ip_length]=$IGNORE_IP
-            let array_ignore_ip_length=$array_ignore_ip_length+1
-        done < ./ignore_ip
-    fi
+ignore_init() {
+  # ignore password
+  array_ignore_pwd_length=0
+  if [ -f ./ignore_pwd ]; then
+    while read IGNORE_PWD
+    do
+      array_ignore_pwd[$array_ignore_pwd_length]=$IGNORE_PWD
+      let array_ignore_pwd_length=$array_ignore_pwd_length+1
+    done < ./ignore_pwd
+  fi
+
+  # ignore ip address
+  array_ignore_ip_length=0
+  if [ -f ./ignore_ip ]; then
+    while read IGNORE_IP
+    do
+      array_ignore_ip[$array_ignore_ip_length]=$IGNORE_IP
+      let array_ignore_ip_length=$array_ignore_ip_length+1
+    done < ./ignore_ip
+  fi
 }
 
-show_version()
-{
-    echo "version: 1.0"
-    echo "updated date: 2014-06-08"
+show_version() {
+  echo "version: 1.0"
+  echo "updated date: 2014-06-08"
 }
 
-show_usage()
-{
-    echo -e "`printf %-16s "Usage: $0"` [-h|--help]"
-        echo -e "`printf %-16s ` [-v|-V|--version]"
-        echo -e "`printf %-16s ` [-l|--iplist ... ]"
-        echo -e "`printf %-16s ` [-c|--config ... ]"
-        echo -e "`printf %-16s ` [-t|--sshtimeout ... ]"
-        echo -e "`printf %-16s ` [-T|--fttimeout ... ]"
-        echo -e "`printf %-16s ` [-L|--bwlimit ... ]"
-        echo -e "`printf %-16s ` [-n|--ignore]"
+show_usage() {
+  echo -e "`printf %-16s "Usage: $0"` [-h|--help]"
+  echo -e "`printf %-16s ` [-v|-V|--version]"
+  echo -e "`printf %-16s ` [-l|--iplist ... ]"
+  echo -e "`printf %-16s ` [-c|--config ... ]"
+  echo -e "`printf %-16s ` [-t|--sshtimeout ... ]"
+  echo -e "`printf %-16s ` [-T|--fttimeout ... ]"
+  echo -e "`printf %-16s ` [-L|--bwlimit ... ]"
+  echo -e "`printf %-16s ` [-n|--ignore]"
 }
 
 IPLIST="iplist.txt"
@@ -60,42 +57,42 @@ TEMP=`getopt -o hvVl:c:t:T:L:n --long help,version,iplist:,config:,sshtimeout:,f
 eval set -- "$TEMP"
 
 while :; do
-    [ -z "$1" ] && break;
-    case "$1" in
-        -h|--help)
-            show_usage; exit 0
-            ;;
-        -v|-V|--version)
-            show_version; exit 0
-            ;;
-        -l|--iplist)
-            IPLIST=$2; shift 2
-            ;;
-        -c|--config)
-            CONFIG_FILE=$2; shift 2
-            ;;
-        -t|--sshtimeout)
-            SSHTIMEOUT=$2; shift 2
-            ;;
-        -T|--fttimeout)
-            SCPTIMEOUT=$2; shift 2
-            ;;
-        -L|--bwlimit)
-            BWLIMIT=$2; shift 2
-            ;;
-        --log)
-            LOG_FILE=$2; shift 2
-            ;;
-        -n|--ignore)
-            IGNRFLAG="ignr"; shift
-            ;;
-        --)
-            shift
-            ;;
-        *)
-            echo -e "\033[31mERROR: unknown argument! \033[0m\n" && show_usage && exit 1
-            ;;
-    esac
+  [ -z "$1" ] && break;
+  case "$1" in
+    -h|--help)
+      show_usage; exit 0
+      ;;
+    -v|-V|--version)
+      show_version; exit 0
+      ;;
+    -l|--iplist)
+      IPLIST=$2; shift 2
+      ;;
+    -c|--config)
+      CONFIG_FILE=$2; shift 2
+      ;;
+    -t|--sshtimeout)
+      SSHTIMEOUT=$2; shift 2
+      ;;
+    -T|--fttimeout)
+      SCPTIMEOUT=$2; shift 2
+      ;;
+    -L|--bwlimit)
+      BWLIMIT=$2; shift 2
+      ;;
+    --log)
+      LOG_FILE=$2; shift 2
+      ;;
+    -n|--ignore)
+      IGNRFLAG="ignr"; shift
+      ;;
+    --)
+      shift
+      ;;
+    *)
+      echo -e "\033[31mERROR: unknown argument! \033[0m\n" && show_usage && exit 1
+      ;;
+  esac
 done
 
 ################  main  #######################
@@ -108,59 +105,59 @@ IP_count=$(egrep -v '^#|^$' $IPLIST|wc -l)
 IP_init=1
 while [[ $IP_init -le $IP_count ]]
 do
-        egrep -v '^#|^$' $IPLIST | sed -n "$IP_init,$(expr $IP_init + 50)p" > $IPLIST.tmp
-
-    IPSEQ=0
-
-    while read IP PORT USER PASSWD PASSWD_2ND PASSWD_3RD PASSWD_4TH OTHERS
-       # while read Line
-        do
-        [ -z "`echo $IP | grep -E '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}|CNS'`" ] && continue
-            if [ "`python ./ckssh.py $IP $PORT`" == 'no' ];then
-            [ ! -e ipnologin.txt ] && > ipnologin.txt
-            [ -z "`grep $IP ipnologin.txt | grep $(date +%F)`" ] && echo "`date +%F_%H%M` $IP" >> ipnologin.txt
-            continue
-            fi
-
-        #[ -e "~/.ssh/known_hosts" ] && grep $IP ~/.ssh/known_hosts | sed -i "/$IP/d" ~/.ssh/known_hosts
-
-        let IPSEQ=$IPSEQ+1
-
-            if [ $IGNRFLAG == "ignr" ]; then
-                    ignore_init
-                    ignored_flag=0
-
-                    i=0
-                    while [ $i -lt $array_ignore_pwd_length ]
-                    do
-                            [ ${PASSWD}x == ${array_ignore_pwd[$i]}x ] && ignored_flag=1 && break
-                            let i=$i+1
-                    done
-
-                    [ $ignored_flag -eq 1 ] && continue
-
-                    j=0
-                    while [ $j -lt $array_ignore_ip_length ]
-                    do
-                            [ ${IP}x == ${array_ignore_ip[$j]}x ] && ignored_flag=1 && break
-                            let j=$j+1
-                    done
-
-                    [ $ignored_flag -eq 1 ] && continue
-            fi
-
-        PASSWD_USE=$PASSWD
-
-                IPcode=$(echo "ibase=16;$(echo "$IP" | xxd -ps -u)"|bc|tr -d '\\'|tr -d '\n')
-                Portcode=$(echo "ibase=16;$(echo "$PORT" | xxd -ps -u)"|bc|tr -d '\\'|tr -d '\n')
-                #USER=$USER
-                PWcode=$(echo "ibase=16;$(echo "$PASSWD_USE" | xxd -ps -u)"|bc|tr -d '\\'|tr -d '\n')
-                Othercode=$(echo "ibase=16;$(echo "$OTHERS" | xxd -ps -u)"|bc|tr -d '\\'|tr -d '\n')
-                #echo $IPcode $Portcode $USER $PWcode $CONFIG_FILE $SSHTIMEOUT $SCPTIMEOUT $BWLIMIT $Othercode
-        ./thread.sh $IPcode $Portcode $USER $PWcode $CONFIG_FILE $SSHTIMEOUT $SCPTIMEOUT $BWLIMIT $Othercode | tee logs/$IP.log &
-        done < $IPLIST.tmp
-        sleep 3
-        IP_init=$(expr $IP_init + 50)
+  egrep -v '^#|^$' $IPLIST | sed -n "$IP_init,$(expr $IP_init + 50)p" > $IPLIST.tmp
+
+  IPSEQ=0
+
+  while read IP PORT USER PASSWD PASSWD_2ND PASSWD_3RD PASSWD_4TH OTHERS
+  # while read Line
+  do
+    [ -z "`echo $IP | grep -E '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}|CNS'`" ] && continue
+    if [ "`python ./ckssh.py $IP $PORT`" == 'no' ]; then
+      [ ! -e ipnologin.txt ] && > ipnologin.txt
+      [ -z "`grep $IP ipnologin.txt | grep $(date +%F)`" ] && echo "`date +%F_%H%M` $IP" >> ipnologin.txt
+      continue
+    fi
+
+    #[ -e "~/.ssh/known_hosts" ] && grep $IP ~/.ssh/known_hosts | sed -i "/$IP/d" ~/.ssh/known_hosts
+
+    let IPSEQ=$IPSEQ+1
+
+    if [ $IGNRFLAG == "ignr" ]; then
+      ignore_init
+      ignored_flag=0
+
+      i=0
+      while [ $i -lt $array_ignore_pwd_length ]
+      do
+        [ ${PASSWD}x == ${array_ignore_pwd[$i]}x ] && ignored_flag=1 && break
+        let i=$i+1
+      done
+
+      [ $ignored_flag -eq 1 ] && continue
+
+      j=0
+      while [ $j -lt $array_ignore_ip_length ]
+      do
+        [ ${IP}x == ${array_ignore_ip[$j]}x ] && ignored_flag=1 && break
+        let j=$j+1
+      done
+
+      [ $ignored_flag -eq 1 ] && continue
+    fi
+
+    PASSWD_USE=$PASSWD
+
+    IPcode=$(echo "ibase=16;$(echo "$IP" | xxd -ps -u)"|bc|tr -d '\\'|tr -d '\n')
+    Portcode=$(echo "ibase=16;$(echo "$PORT" | xxd -ps -u)"|bc|tr -d '\\'|tr -d '\n')
+    #USER=$USER
+    PWcode=$(echo "ibase=16;$(echo "$PASSWD_USE" | xxd -ps -u)"|bc|tr -d '\\'|tr -d '\n')
+    Othercode=$(echo "ibase=16;$(echo "$OTHERS" | xxd -ps -u)"|bc|tr -d '\\'|tr -d '\n')
+    #echo $IPcode $Portcode $USER $PWcode $CONFIG_FILE $SSHTIMEOUT $SCPTIMEOUT $BWLIMIT $Othercode
+    ./thread.sh $IPcode $Portcode $USER $PWcode $CONFIG_FILE $SSHTIMEOUT $SCPTIMEOUT $BWLIMIT $Othercode | tee logs/$IP.log &
+  done < $IPLIST.tmp
+  sleep 3
+  IP_init=$(expr $IP_init + 50)
 done
 
 ENDDATETIME=`date "+%F %T"`

+ 70 - 70
tools/mscp.exp

@@ -1,23 +1,23 @@
 #!/usr/bin/expect --
 
 proc Usage_Exit {self} {
-    puts ""
-    puts "Usage: $self ip user passwd port sourcefile destdir direction bwlimit timeout"
-    puts ""
-    puts "       sourcefile: a file or directory to be transferred"
-    puts "                   需要拷贝目录时目录名后不要带 /, 否则会拷贝该目录下的所有文件"
-    puts "       destdir:    the location that the sourcefile to be put into"
-    puts "       direction:  pull or push"
-    puts "                   pull: remote -> local"
-    puts "                   push: local -> remote"
-    puts "       bwlimit:    bandwidth limit, kbit/s, 0 means no limit"
-    puts "       timeout:    timeout of expect, s, -1 means no timeout"
-    puts ""
-    exit 1
+  puts ""
+  puts "Usage: $self ip user passwd port sourcefile destdir direction bwlimit timeout"
+  puts ""
+  puts "       sourcefile: a file or directory to be transferred"
+  puts "                   需要拷贝目录时目录名后不要带 /, 否则会拷贝该目录下的所有文件"
+  puts "       destdir:    the location that the sourcefile to be put into"
+  puts "       direction:  pull or push"
+  puts "                   pull: remote -> local"
+  puts "                   push: local -> remote"
+  puts "       bwlimit:    bandwidth limit, kbit/s, 0 means no limit"
+  puts "       timeout:    timeout of expect, s, -1 means no timeout"
+  puts ""
+  exit 1
 }
 
 if { [llength $argv] < 9 } {
-    Usage_Exit $argv0
+  Usage_Exit $argv0
 }
 
 set ipcode [lindex $argv 0]
@@ -37,122 +37,122 @@ set yesnoflag 0
 set timeout $timeoutflag
 
 for {} {1} {} {
-# for is only used to retry when "Interrupted system call" occured
+  # for is only used to retry when "Interrupted system call" occured
 
-if { $direction == "pull" } {
+  if { $direction == "pull" } {
 
     if { $bwlimit > 0 } {
-        spawn rsync -crazP --delete --bwlimit=$bwlimit -e "/usr/bin/ssh -o GSSAPIAuthentication=no -q -l$user -p$port" $ip:$sourcefile $destdir
+      spawn rsync -crazP --delete --bwlimit=$bwlimit -e "/usr/bin/ssh -o GSSAPIAuthentication=no -q -l$user -p$port" $ip:$sourcefile $destdir
     } elseif { $bwlimit == 0 } {
-        spawn rsync -crazP --delete -e "/usr/bin/ssh -o GSSAPIAuthentication=no -q -l$user -p$port" $ip:$sourcefile $destdir
+      spawn rsync -crazP --delete -e "/usr/bin/ssh -o GSSAPIAuthentication=no -q -l$user -p$port" $ip:$sourcefile $destdir
     } else {
-        Usage_Exit $argv0
+      Usage_Exit $argv0
     }
 
-} elseif { $direction == "push" } {
+  } elseif { $direction == "push" } {
 
     if { $bwlimit > 0 } {
-        spawn rsync -crazP --delete --bwlimit=$bwlimit -e "/usr/bin/ssh -o GSSAPIAuthentication=no -q -l$user -p$port" $sourcefile $ip:$destdir
+      spawn rsync -crazP --delete --bwlimit=$bwlimit -e "/usr/bin/ssh -o GSSAPIAuthentication=no -q -l$user -p$port" $sourcefile $ip:$destdir
     } elseif { $bwlimit == 0 } {
-        spawn rsync -crazP --delete -e "/usr/bin/ssh -o GSSAPIAuthentication=no -q -l$user -p$port" $sourcefile $ip:$destdir
+      spawn rsync -crazP --delete -e "/usr/bin/ssh -o GSSAPIAuthentication=no -q -l$user -p$port" $sourcefile $ip:$destdir
     } else {
-        Usage_Exit $argv0
+      Usage_Exit $argv0
     }
 
-} else {
+  } else {
     Usage_Exit $argv0
-}
+  }
 
-expect  {
+  expect {
 
     "assword:" {
-        send "$passwd\r"
-        break;
+      send "$passwd\r"
+      break;
     }
 
     "yes/no)?" {
-        set yesnoflag 1
-        send "yes\r"
-        break;
+      set yesnoflag 1
+      send "yes\r"
+      break;
     }
 
     "FATAL" {
-        puts "\nCONNECTERROR: $ip occur FATAL ERROR!!!\n"
-        exit 1
+      puts "\nCONNECTERROR: $ip occur FATAL ERROR!!!\n"
+      exit 1
     }
 
     timeout {
-        puts "\nCONNECTERROR: $ip Logon timeout!!!\n"
-        exit 1
+      puts "\nCONNECTERROR: $ip Logon timeout!!!\n"
+      exit 1
     }
 
     "No route to host" {
-        puts "\nCONNECTERROR: $ip No route to host!!!\n"
-        exit 1
+      puts "\nCONNECTERROR: $ip No route to host!!!\n"
+      exit 1
     }
 
     "Connection Refused" {
-        puts "\nCONNECTERROR: $ip Connection Refused!!!\n"
-        exit 1
+      puts "\nCONNECTERROR: $ip Connection Refused!!!\n"
+      exit 1
     }
 
     "Connection refused" {
-        puts "\nCONNECTERROR: $ip Connection Refused!!!\n"
-        exit 1
+      puts "\nCONNECTERROR: $ip Connection Refused!!!\n"
+      exit 1
     }
 
     "Host key verification failed" {
-        puts "\nCONNECTERROR: $ip Host key verification failed!!!\n"
-        exit 1
+      puts "\nCONNECTERROR: $ip Host key verification failed!!!\n"
+      exit 1
     }
 
     "Illegal host key" {
-        puts "\nCONNECTERROR: $ip Illegal host key!!!\n"
-        exit 1
+      puts "\nCONNECTERROR: $ip Illegal host key!!!\n"
+      exit 1
     }
 
     "Connection Timed Out" {
-        puts "\nCONNECTERROR: $ip Logon timeout!!!\n"
-        exit 1
+      puts "\nCONNECTERROR: $ip Logon timeout!!!\n"
+      exit 1
     }
 
     "Interrupted system call" {
-        puts "\n$ip Interrupted system call!!!\n"
+      puts "\n$ip Interrupted system call!!!\n"
     }
-}
+  }
 
 }
 
 if { $yesnoflag == 1 } {
-    expect {
-        "assword:" {
-            send "$passwd\r"
-        }
+  expect {
+    "assword:" {
+      send "$passwd\r"
+    }
 
-        "yes/no)?" {
-            set yesnoflag 2
-            send "yes\r"
-        }
+    "yes/no)?" {
+      set yesnoflag 2
+      send "yes\r"
     }
+  }
 }
 
 if { $yesnoflag == 2 } {
-    expect {
-        "assword:" {
-            send "$passwd\r"
-        }
+  expect {
+    "assword:" {
+      send "$passwd\r"
     }
+  }
 }
 
 expect {
-    "assword:" {
-        send "$passwd\r"
-        puts "\nPASSWORDERROR: $ip Password error!!!\n"
-        exit 1
-    }
+  "assword:" {
+    send "$passwd\r"
+    puts "\nPASSWORDERROR: $ip Password error!!!\n"
+    exit 1
+  }
 
-    eof {
-        puts "OK_SCP: $ip\n"
-        exit 0;
-    }
+  eof {
+    puts "OK_SCP: $ip\n"
+    exit 0;
+  }
 }

+ 51 - 51
tools/mssh.exp

@@ -1,8 +1,8 @@
 #!/usr/bin/expect --
 
 if { [llength $argv] < 4 } {
-    puts "Usage: $argv0 ip user passwd port commands timeout"
-    exit 1
+  puts "Usage: $argv0 ip user passwd port commands timeout"
+  exit 1
 }
 
 match_max 600000
@@ -22,108 +22,108 @@ set timeout $timeoutflag
 
 
 for {} {1} {} {
-# for is only used to retry when "Interrupted system call" occured
+  # for is only used to retry when "Interrupted system call" occured
 
-spawn /usr/bin/ssh -o GSSAPIAuthentication=no -q -l$user -p$port $ip
+  spawn /usr/bin/ssh -o GSSAPIAuthentication=no -q -l$user -p$port $ip
 
-expect  {
+  expect  {
 
     "assword:" {
-        send "$passwd\r"
-        break;
+      send "$passwd\r"
+      break;
     }
 
     "yes/no)?" {
-        set yesnoflag 1
-        send "yes\r"
-        break;
+      set yesnoflag 1
+      send "yes\r"
+      break;
     }
 
     "FATAL" {
-        puts "\nCONNECTERROR: $ip occur FATAL ERROR!!!\n"
-        exit 1
+      puts "\nCONNECTERROR: $ip occur FATAL ERROR!!!\n"
+      exit 1
     }
 
     timeout {
-        puts "\nCONNECTERROR: $ip Logon timeout!!!\n"
-        exit 1
+      puts "\nCONNECTERROR: $ip Logon timeout!!!\n"
+      exit 1
     }
 
     "No route to host" {
-        puts "\nCONNECTERROR: $ip No route to host!!!\n"
-        exit 1
+      puts "\nCONNECTERROR: $ip No route to host!!!\n"
+      exit 1
     }
 
     "Connection Refused" {
-        puts "\nCONNECTERROR: $ip Connection Refused!!!\n"
-        exit 1
+      puts "\nCONNECTERROR: $ip Connection Refused!!!\n"
+      exit 1
     }
 
     "Connection refused" {
-        puts "\nCONNECTERROR: $ip Connection Refused!!!\n"
-        exit 1
+      puts "\nCONNECTERROR: $ip Connection Refused!!!\n"
+      exit 1
     }
 
     "Host key verification failed" {
-        puts "\nCONNECTERROR: $ip Host key verification failed!!!\n"
-        exit 1
+      puts "\nCONNECTERROR: $ip Host key verification failed!!!\n"
+      exit 1
     }
 
     "Illegal host key" {
-        puts "\nCONNECTERROR: $ip Illegal host key!!!\n"
-        exit 1
+      puts "\nCONNECTERROR: $ip Illegal host key!!!\n"
+      exit 1
     }
 
     "Connection Timed Out" {
-        puts "\nCONNECTERROR: $ip Logon timeout!!!\n"
-        exit 1
+      puts "\nCONNECTERROR: $ip Logon timeout!!!\n"
+      exit 1
     }
 
     "Interrupted system call" {
-        puts "\n$ip Interrupted system call!!!\n"
+      puts "\n$ip Interrupted system call!!!\n"
     }
-}
+  }
 }
 
 if { $yesnoflag == 1 } {
-    expect {
-        "assword:" {
-            send "$passwd\r"
-        }
-
-        "yes/no)?" {
-            set yesnoflag 2
-            send "yes\r"
-        }
+  expect {
+    "assword:" {
+      send "$passwd\r"
+    }
+
+    "yes/no)?" {
+      set yesnoflag 2
+      send "yes\r"
     }
+  }
 }
 
 if { $yesnoflag == 2 } {
-    expect {
-        "assword:" {
-            send "$passwd\r"
-        }
+  expect {
+    "assword:" {
+      send "$passwd\r"
     }
+  }
 }
 
 expect {
-    "@" {send "$commands \r"}
-    "assword:" {
-        send "$passwd\r"
-        puts "\nPASSWORDERROR: $ip Password error!!!\n"
-        exit 1
-    }
+  "@" {send "$commands \r"}
+  "assword:" {
+    send "$passwd\r"
+    puts "\nPASSWORDERROR: $ip Password error!!!\n"
+    exit 1
+  }
 }
 
 expect {
-    "@" {send "sleep 1\r"}
+  "@" {send "sleep 1\r"}
 }
 
 expect {
-    "@" {send "exit\r"}
+  "@" {send "exit\r"}
 }
 
 expect eof {
-    puts "OK_SSH: $ip\n"
-    exit 0;
+  puts "OK_SSH: $ip\n"
+  exit 0;
 }

+ 24 - 24
tools/thread.sh

@@ -16,30 +16,30 @@ BWLIMIT=$8
 
 while read eachline
 do
-    [ -z "`echo $eachline | grep -E '^com|^file'`" ] && continue
-
-    myKEYWORD=`echo $eachline | awk -F"$myIFS" '{ print $1 }'`
-    myCONFIGLINE=`echo $eachline | awk -F"$myIFS" '{ print $2 }'`
-
-    if [ "$myKEYWORD"x == "file"x ]; then
-        SOURCEFILE=`echo $myCONFIGLINE | awk '{ print $1 }'`
-        DESTDIR=`echo $myCONFIGLINE | awk '{ print $2 }'`
-        DIRECTION=`echo $myCONFIGLINE | awk '{ print $3 }'`
-        ./mscp.exp $IP $USER $PASSWD $PORT $SOURCEFILE $DESTDIR $DIRECTION $BWLIMIT $SCPTIMEOUT
-
-        [ $? -ne 0 ] && echo -e "\033[31mSCP Try Out All Password Failed\033[0m\n"
-
-    elif [ "$myKEYWORD"x == "com"x ]; then
-        ./mssh.exp $IP $USER $PASSWD $PORT "${myCONFIGLINE}" $SSHTIMEOUT
-        [ $? -ne 0 ] && echo -e "\033[31mSSH Try Out All Password Failed\033[0m\n"
-
-    else
-        echo "ERROR: configuration wrong! [$eachline] "
-        echo "       where KEYWORD should not be [$myKEYWORD], but 'com' or 'file'"
-        echo "       if you dont want to run it, you can comment it with '#'"
-        echo ""
-        exit
-    fi
+  [ -z "`echo $eachline | grep -E '^com|^file'`" ] && continue
+
+  myKEYWORD=`echo $eachline | awk -F"$myIFS" '{ print $1 }'`
+  myCONFIGLINE=`echo $eachline | awk -F"$myIFS" '{ print $2 }'`
+
+  if [ "$myKEYWORD"x == "file"x ]; then
+    SOURCEFILE=`echo $myCONFIGLINE | awk '{ print $1 }'`
+    DESTDIR=`echo $myCONFIGLINE | awk '{ print $2 }'`
+    DIRECTION=`echo $myCONFIGLINE | awk '{ print $3 }'`
+    ./mscp.exp $IP $USER $PASSWD $PORT $SOURCEFILE $DESTDIR $DIRECTION $BWLIMIT $SCPTIMEOUT
+
+    [ $? -ne 0 ] && echo -e "\033[31mSCP Try Out All Password Failed\033[0m\n"
+
+  elif [ "$myKEYWORD"x == "com"x ]; then
+    ./mssh.exp $IP $USER $PASSWD $PORT "${myCONFIGLINE}" $SSHTIMEOUT
+    [ $? -ne 0 ] && echo -e "\033[31mSSH Try Out All Password Failed\033[0m\n"
+
+  else
+    echo "ERROR: configuration wrong! [$eachline] "
+    echo "       where KEYWORD should not be [$myKEYWORD], but 'com' or 'file'"
+    echo "       if you dont want to run it, you can comment it with '#'"
+    echo ""
+    exit
+  fi
 
 done < $CONFIG_FILE
 

+ 15 - 15
tools/website_bk.sh

@@ -18,21 +18,21 @@ OldFile=$backup_dir/Web_${WebSite}_$(date +%Y%m%d --date="$expired_days days ago
 [ ! -e "$wwwroot_dir/$WebSite" ] && { echo "[$wwwroot_dir/$WebSite] not exist" >> $LogFile ;  exit 1 ; }
 
 if [ `du -sm "$wwwroot_dir/$WebSite" | awk '{print $1}'` -lt 1024 ];then
-    if [ -n "`ls $OldFile 2>/dev/null`" ];then
-        /bin/rm -f $OldFile
-        echo "[$OldFile] Delete Old File Success" >> $LogFile
-    else
-        echo "[$OldFile] Delete Old Backup File" >> $LogFile
-    fi
+  if [ -n "`ls $OldFile 2>/dev/null`" ];then
+    /bin/rm -f $OldFile
+    echo "[$OldFile] Delete Old File Success" >> $LogFile
+  else
+    echo "[$OldFile] Delete Old Backup File" >> $LogFile
+  fi
 
-    if [ -e "$NewFile" ];then
-        echo "[$NewFile] The Backup File is exists, Can't Backup" >> $LogFile
-    else
-        cd $wwwroot_dir
-        tar czf $NewFile ./${WebSite} >> $LogFile 2>&1
-        echo "[$NewFile] Backup success ">> $LogFile
-        cd -
-    fi
+  if [ -e "$NewFile" ];then
+    echo "[$NewFile] The Backup File is exists, Can't Backup" >> $LogFile
+  else
+    pushd $wwwroot_dir > /dev/null
+    tar czf $NewFile ./${WebSite} >> $LogFile 2>&1
+    echo "[$NewFile] Backup success ">> $LogFile
+    popd > /dev/null
+  fi
 else
-    rsync -crazP --delete $wwwroot_dir/$WebSite $backup_dir
+  rsync -crazP --delete $wwwroot_dir/$WebSite $backup_dir
 fi