【美高梅手机版4858】nginx随机运行脚本,rsync随机运维脚本

By admin in 美高梅手机版4858 on 2019年4月18日

服务端

服务端

rsync随机运营脚本,rsync脚本

服务端

 

美高梅手机版4858 1

 1 #!/bin/sh
 2 # chkconfig: 2345 21 60
 3 # description: Saves and restores system entropy pool for \
 4 #create by xiaohu
 5 #2014.06.02
 6 #This script is the Rsync service script
 7 . /etc/init.d/functions
 8 case "$1" in
 9   start)
10         echo "rsync is starting"
11         /usr/local/rsyncd/bin/rsync --daemon --config=/etc/rsyncd.conf
12         sleep 2
13         myport=`netstat -lnt|grep 873|wc -l`
14         if [ $myport -eq 2 ]
15         then
16         action "rsync start"   /bin/true
17         else
18         action "rsync start"   /bin/false
19         fi
20         ;;
21   stop)
22         echo "rsync is stoping"
23         myport=`netstat -lnt|grep 873|wc -l`
24         if [ $myport -eq 2 ]
25         then 
26         killall rsync &>/dev/null
27         sleep 2
28         killall rsync &>/dev/null
29         sleep 1
30         fi
31         myport=`netstat -lnt|grep 873|wc -l`
32         if [ $myport -ne 2 ]
33         then
34         action "rsync stop"   /bin/true
35         else
36         action "rsync stop"   /bin/false
37         fi
38         ;;
39   restart)
40         if [ `netstat -lnt|grep 873|wc -l` -eq 0 ]
41         then
42         /usr/local/rsyncd/bin/rsync --daemon --config=/etc/rsyncd.conf
43         sleep 2
44         myport=`netstat -lnt|grep 873|wc -l`
45         if [ $myport -eq 2 ]
46         then
47         action "rsync restart"   /bin/true
48         else
49         action "rsync restart"   /bin/false
50         exit
51         fi
52         else
53         killall rsync &>/dev/null
54         sleep 2
55         killall rsync &>/dev/null
56         sleep 1
57         /usr/local/rsyncd/bin/rsync --daemon --config=/etc/rsyncd.conf
58         sleep 2
59         myport=`netstat -lnt|grep 873|wc -l`
60         if [ $myport -eq 2 ]
61         then
62         action "rsync restart"   /bin/true
63         else
64         action "rsync restart"   /bin/false
65         fi
66         fi
67         ;;
68   status)
69         myport=`netstat -lnt|grep 873|wc -l`
70         if [ $myport -eq 2 ]
71         then
72         echo  "rsync is running"
73         else
74         echo "rsync is stoped"
75         fi
76         ;;
77   *)
78         echo $"Usage: $0 {start|stop|status|restart}"
79         ;;
80 esac

View Code

 

 

客户端

 

美高梅手机版4858 2

  1 #! /bin/sh
  2 
  3 ### BEGIN INIT INFO
  4 # Provides:          rsyncd
  5 # Required-Start:    $remote_fs $syslog
  6 # Required-Stop:     $remote_fs $syslog
  7 # Should-Start:      $named autofs
  8 # Default-Start:     2 3 4 5
  9 # Default-Stop:      
 10 # Short-Description: fast remote file copy program daemon
 11 # Description:       rsync is a program that allows files to be copied to and
 12 #                    from remote machines in much the same way as rcp.
 13 #                    This provides rsyncd daemon functionality.
 14 ### END INIT INFO
 15 
 16 set -e
 17 
 18 # /etc/init.d/rsync: start and stop the rsync daemon
 19 
 20 DAEMON=/usr/bin/rsync
 21 RSYNC_ENABLE=false
 22 RSYNC_OPTS=''
 23 RSYNC_DEFAULTS_FILE=/etc/default/rsync
 24 RSYNC_CONFIG_FILE=/etc/rsyncd.conf
 25 RSYNC_PID_FILE=/var/run/rsync.pid
 26 RSYNC_NICE_PARM=''
 27 RSYNC_IONICE_PARM=''
 28 
 29 test -x $DAEMON || exit 0
 30 
 31 . /lib/lsb/init-functions
 32 
 33 if [ -s $RSYNC_DEFAULTS_FILE ]; then
 34     . $RSYNC_DEFAULTS_FILE
 35     case "x$RSYNC_ENABLE" in
 36     xtrue|xfalse)    ;;
 37     xinetd)        exit 0
 38             ;;
 39     *)        log_failure_msg "Value of RSYNC_ENABLE in $RSYNC_DEFAULTS_FILE must be either 'true' or 'false';"
 40             log_failure_msg "not starting rsync daemon."
 41             exit 1
 42             ;;
 43     esac
 44     case "x$RSYNC_NICE" in
 45     x[0-9]|x1[0-9])    RSYNC_NICE_PARM="--nicelevel $RSYNC_NICE";;
 46     x)        ;;
 47     *)        log_warning_msg "Value of RSYNC_NICE in $RSYNC_DEFAULTS_FILE must be a value between 0 and 19 (inclusive);"
 48             log_warning_msg "ignoring RSYNC_NICE now."
 49             ;;
 50     esac
 51     case "x$RSYNC_IONICE" in
 52     x-c[123]*)    RSYNC_IONICE_PARM="$RSYNC_IONICE";;
 53     x)        ;;
 54     *)        log_warning_msg "Value of RSYNC_IONICE in $RSYNC_DEFAULTS_FILE must be -c1, -c2 or -c3;"
 55             log_warning_msg "ignoring RSYNC_IONICE now."
 56             ;;
 57     esac
 58 fi
 59 
 60 export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
 61 
 62 rsync_start() {
 63     if [ ! -s "$RSYNC_CONFIG_FILE" ]; then
 64         log_failure_msg "missing or empty config file $RSYNC_CONFIG_FILE"
 65         log_end_msg 1
 66         exit 0
 67     fi
 68     # See ionice(1)
 69     if [ -n "$RSYNC_IONICE_PARM" ] && [ -x /usr/bin/ionice ] &&
 70         /usr/bin/ionice "$RSYNC_IONICE_PARM" true 2>/dev/null; then
 71         /usr/bin/ionice "$RSYNC_IONICE_PARM" -p$$ > /dev/null 2>&1
 72     fi
 73     if start-stop-daemon --start --quiet --background \
 74         --pidfile $RSYNC_PID_FILE --make-pidfile \
 75         $RSYNC_NICE_PARM --exec $DAEMON \
 76         -- --no-detach --daemon --config "$RSYNC_CONFIG_FILE" $RSYNC_OPTS
 77     then
 78         rc=0
 79         sleep 1
 80         if ! kill -0 $(cat $RSYNC_PID_FILE) >/dev/null 2>&1; then
 81             log_failure_msg "rsync daemon failed to start"
 82             rc=1
 83         fi
 84     else
 85         rc=1
 86     fi
 87     if [ $rc -eq 0 ]; then
 88         log_end_msg 0
 89     else
 90         log_end_msg 1
 91         rm -f $RSYNC_PID_FILE
 92     fi
 93 } # rsync_start
 94 
 95 
 96 case "$1" in
 97   start)
 98     if "$RSYNC_ENABLE"; then
 99         log_daemon_msg "Starting rsync daemon" "rsync"
100         if [ -s $RSYNC_PID_FILE ] && kill -0 $(cat $RSYNC_PID_FILE) >/dev/null 2>&1; then
101         log_progress_msg "apparently already running"
102         log_end_msg 0
103         exit 0
104         fi
105             rsync_start
106         else
107             if [ -s "$RSYNC_CONFIG_FILE" ]; then
108                 [ "$VERBOSE" != no ] && log_warning_msg "rsync daemon not enabled in $RSYNC_DEFAULTS_FILE, not starting..."
109             fi
110     fi
111     ;;
112   stop)
113     log_daemon_msg "Stopping rsync daemon" "rsync"
114     start-stop-daemon --stop --quiet --oknodo --pidfile $RSYNC_PID_FILE
115     log_end_msg $?
116     rm -f $RSYNC_PID_FILE
117     ;;
118 
119   reload|force-reload)
120     log_warning_msg "Reloading rsync daemon: not needed, as the daemon"
121     log_warning_msg "re-reads the config file whenever a client connects."
122     ;;
123 
124   restart)
125     set +e
126     if $RSYNC_ENABLE; then
127         log_daemon_msg "Restarting rsync daemon" "rsync"
128         if [ -s $RSYNC_PID_FILE ] && kill -0 $(cat $RSYNC_PID_FILE) >/dev/null 2>&1; then
129         start-stop-daemon --stop --quiet --oknodo --pidfile $RSYNC_PID_FILE || true
130         sleep 1
131         else
132         log_warning_msg "rsync daemon not running, attempting to start."
133             rm -f $RSYNC_PID_FILE
134         fi
135             rsync_start
136         else
137             if [ -s "$RSYNC_CONFIG_FILE" ]; then
138                 [ "$VERBOSE" != no ] && log_warning_msg "rsync daemon not enabled in $RSYNC_DEFAULTS_FILE, not starting..."
139             fi
140     fi
141     ;;
142 
143   status)
144     status_of_proc -p $RSYNC_PID_FILE "$DAEMON" rsync
145     exit $?    # notreached due to set -e
146     ;;
147   *)
148     echo "Usage: /etc/init.d/rsync {start|stop|reload|force-reload|restart|status}"
149     exit 1
150 esac
151 
152 exit 0

View Code

 

 


开机自动运转rsync

  1. 扔脚本进去/etc/init.d/
  1. 授权
    chmod +x rsync
  1. 如若抛出:binsh^M错误就进行编码改写
    安装dos统一编码
    (请看rsync脚本抛出binsh^M bad interpreter文书档案)
  1. 拉长到劳动
    chkconfig –add ningx
  1. 随意运维脚本拉动rsync开机运转
    chkconfig –level 2345 rsync on

 

 


 

施行脚本时意识如下错误:
/bin/sh^M: bad interpreter: 没有那个文件或目录

不当分析:
因为操作系统是windows,作者在windows下编写制定的本子,所以有希望有不可见字符。
剧本文件是DOS格式的, 即每一行的行尾以\n\r来标记, 其ASCII码分别是0x0D,
0x0A.

能够有很各个措施看那么些文件是DOS格式的依然UNIX格式的, 还是MAC格式的

解决办法:
vim filename
然后用命令
:set ff? #【美高梅手机版4858】nginx随机运行脚本,rsync随机运维脚本。能够看出dos或unix的字样. 就算确实是dos格式的。

然后用
:set ff=unix #把它强制为unix格式的, 然后存盘退出。
双重运营脚本。

 

服务端 1 #!/bin/ sh
2 # chkconfig: 2345 21 60 3 # description: Saves and restores system
entropy pool for \ 4 #create by xiaohu 5 # 2014.06…

 

 

开机自动运转nginx

一.    扔脚本进去/etc/init.d/

2.    授权
     chmod +x nginx

三.    壹旦抛出:binsh^M错误就试行编码改写
     设置dos统一编码
     (请看nginx脚本抛出binsh^M bad interpreter文书档案)

肆.    加多到服务
     chkconfig –add ningx
    
    
5.    随机运行脚本带动nginx开机运行
     chkconfig –level 2345 nginx on


依附脚本

#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig:   - 85 15
# description:  NGINX is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /etc/nginx/nginx.conf
# config:      /etc/sysconfig/nginx
# pidfile:     /var/run/nginx.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)

NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx

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
}

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
}

stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}

restart() {
    configtest || return $?
    stop
    sleep 1
    start
}

reload() {
    configtest || return $?
    echo -n $"Reloading $prog: "
    killproc $nginx -HUP
    RETVAL=$?
    echo
}

force_reload() {
    restart
}

configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}

rh_status() {
    status $prog
}

rh_status_q() {
    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
esac

施行脚本时发现如下错误:
/bin/sh^M: bad interpreter: 未有十二分文件或目录
 
漏洞非常多分析:
因为操作系统是windows,小编在windows下编写制定的脚本,所以有十分的大可能率有不可知字符。
本子文件是DOS格式的, 即每1行的行尾以\n\r来标记, 其ASCII码分别是0x0D,
0x0A.
 
能够有很三种方法看那一个文件是DOS格式的依旧UNIX格式的, 照旧MAC格式的
 
缓解方式:
vim filename
然后用命令
:set ff? #能够看到dos或unix的字样. 若是实在是dos格式的。
 
 
然后用
:set ff=unix #把它强制为unix格式的, 然后存盘退出。
再次运转脚本。


在RedHat 6上编写翻译安装openssl后,运维openssl version出现如下错误:

[html] view plain copy
openssl: error while loading shared libraries: libssl.so.1.1: cannot
open shared object file: No such file or directory 

这是由于openssl库的岗位不得法造成的。

斩草除根办法:

在root用户下施行:

[html] view plain copy
ln -s /usr/local/lib64/libssl.so.1.1 /usr/lib64/libssl.so.1.1 
ln -s /usr/local/lib64/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1 

美高梅手机版4858 3美高梅手机版4858 4

美高梅手机版4858 5美高梅手机版4858 6

 1 #!/bin/sh
 2 # chkconfig: 2345 21 60
 3 # description: Saves and restores system entropy pool for \
 4 #create by xiaohu
 5 #2014.06.02
 6 #This script is the Rsync service script
 7 . /etc/init.d/functions
 8 case "$1" in
 9   start)
10         echo "rsync is starting"
11         /usr/local/rsyncd/bin/rsync --daemon --config=/etc/rsyncd.conf
12         sleep 2
13         myport=`netstat -lnt|grep 873|wc -l`
14         if [ $myport -eq 2 ]
15         then
16         action "rsync start"   /bin/true
17         else
18         action "rsync start"   /bin/false
19         fi
20         ;;
21   stop)
22         echo "rsync is stoping"
23         myport=`netstat -lnt|grep 873|wc -l`
24         if [ $myport -eq 2 ]
25         then 
26         killall rsync &>/dev/null
27         sleep 2
28         killall rsync &>/dev/null
29         sleep 1
30         fi
31         myport=`netstat -lnt|grep 873|wc -l`
32         if [ $myport -ne 2 ]
33         then
34         action "rsync stop"   /bin/true
35         else
36         action "rsync stop"   /bin/false
37         fi
38         ;;
39   restart)
40         if [ `netstat -lnt|grep 873|wc -l` -eq 0 ]
41         then
42         /usr/local/rsyncd/bin/rsync --daemon --config=/etc/rsyncd.conf
43         sleep 2
44         myport=`netstat -lnt|grep 873|wc -l`
45         if [ $myport -eq 2 ]
46         then
47         action "rsync restart"   /bin/true
48         else
49         action "rsync restart"   /bin/false
50         exit
51         fi
52         else
53         killall rsync &>/dev/null
54         sleep 2
55         killall rsync &>/dev/null
56         sleep 1
57         /usr/local/rsyncd/bin/rsync --daemon --config=/etc/rsyncd.conf
58         sleep 2
59         myport=`netstat -lnt|grep 873|wc -l`
60         if [ $myport -eq 2 ]
61         then
62         action "rsync restart"   /bin/true
63         else
64         action "rsync restart"   /bin/false
65         fi
66         fi
67         ;;
68   status)
69         myport=`netstat -lnt|grep 873|wc -l`
70         if [ $myport -eq 2 ]
71         then
72         echo  "rsync is running"
73         else
74         echo "rsync is stoped"
75         fi
76         ;;
77   *)
78         echo $"Usage: $0 {start|stop|status|restart}"
79         ;;
80 esac
 1 #!/bin/sh
 2 # chkconfig: 2345 21 60
 3 # description: Saves and restores system entropy pool for \
 4 #create by xiaohu
 5 #2014.06.02
 6 #This script is the Rsync service script
 7 . /etc/init.d/functions
 8 case "$1" in
 9   start)
10         echo "rsync is starting"
11         /usr/local/rsyncd/bin/rsync --daemon --config=/etc/rsyncd.conf
12         sleep 2
13         myport=`netstat -lnt|grep 873|wc -l`
14         if [ $myport -eq 2 ]
15         then
16         action "rsync start"   /bin/true
17         else
18         action "rsync start"   /bin/false
19         fi
20         ;;
21   stop)
22         echo "rsync is stoping"
23         myport=`netstat -lnt|grep 873|wc -l`
24         if [ $myport -eq 2 ]
25         then 
26         killall rsync &>/dev/null
27         sleep 2
28         killall rsync &>/dev/null
29         sleep 1
30         fi
31         myport=`netstat -lnt|grep 873|wc -l`
32         if [ $myport -ne 2 ]
33         then
34         action "rsync stop"   /bin/true
35         else
36         action "rsync stop"   /bin/false
37         fi
38         ;;
39   restart)
40         if [ `netstat -lnt|grep 873|wc -l` -eq 0 ]
41         then
42         /usr/local/rsyncd/bin/rsync --daemon --config=/etc/rsyncd.conf
43         sleep 2
44         myport=`netstat -lnt|grep 873|wc -l`
45         if [ $myport -eq 2 ]
46         then
47         action "rsync restart"   /bin/true
48         else
49         action "rsync restart"   /bin/false
50         exit
51         fi
52         else
53         killall rsync &>/dev/null
54         sleep 2
55         killall rsync &>/dev/null
56         sleep 1
57         /usr/local/rsyncd/bin/rsync --daemon --config=/etc/rsyncd.conf
58         sleep 2
59         myport=`netstat -lnt|grep 873|wc -l`
60         if [ $myport -eq 2 ]
61         then
62         action "rsync restart"   /bin/true
63         else
64         action "rsync restart"   /bin/false
65         fi
66         fi
67         ;;
68   status)
69         myport=`netstat -lnt|grep 873|wc -l`
70         if [ $myport -eq 2 ]
71         then
72         echo  "rsync is running"
73         else
74         echo "rsync is stoped"
75         fi
76         ;;
77   *)
78         echo $"Usage: $0 {start|stop|status|restart}"
79         ;;
80 esac

View Code

View Code

 

 

 

 

客户端

客户端

 

 

美高梅手机版4858 7美高梅手机版4858 8

美高梅手机版4858 9美高梅手机版4858 10

  1 #! /bin/sh
  2 
  3 ### BEGIN INIT INFO
  4 # Provides:          rsyncd
  5 # Required-Start:    $remote_fs $syslog
  6 # Required-Stop:     $remote_fs $syslog
  7 # Should-Start:      $named autofs
  8 # Default-Start:     2 3 4 5
  9 # Default-Stop:      
 10 # Short-Description: fast remote file copy program daemon
 11 # Description:       rsync is a program that allows files to be copied to and
 12 #                    from remote machines in much the same way as rcp.
 13 #                    This provides rsyncd daemon functionality.
 14 ### END INIT INFO
 15 
 16 set -e
 17 
 18 # /etc/init.d/rsync: start and stop the rsync daemon
 19 
 20 DAEMON=/usr/bin/rsync
 21 RSYNC_ENABLE=false
 22 RSYNC_OPTS=''
 23 RSYNC_DEFAULTS_FILE=/etc/default/rsync
 24 RSYNC_CONFIG_FILE=/etc/rsyncd.conf
 25 RSYNC_PID_FILE=/var/run/rsync.pid
 26 RSYNC_NICE_PARM=''
 27 RSYNC_IONICE_PARM=''
 28 
 29 test -x $DAEMON || exit 0
 30 
 31 . /lib/lsb/init-functions
 32 
 33 if [ -s $RSYNC_DEFAULTS_FILE ]; then
 34     . $RSYNC_DEFAULTS_FILE
 35     case "x$RSYNC_ENABLE" in
 36     xtrue|xfalse)    ;;
 37     xinetd)        exit 0
 38             ;;
 39     *)        log_failure_msg "Value of RSYNC_ENABLE in $RSYNC_DEFAULTS_FILE must be either 'true' or 'false';"
 40             log_failure_msg "not starting rsync daemon."
 41             exit 1
 42             ;;
 43     esac
 44     case "x$RSYNC_NICE" in
 45     x[0-9]|x1[0-9])    RSYNC_NICE_PARM="--nicelevel $RSYNC_NICE";;
 46     x)        ;;
 47     *)        log_warning_msg "Value of RSYNC_NICE in $RSYNC_DEFAULTS_FILE must be a value between 0 and 19 (inclusive);"
 48             log_warning_msg "ignoring RSYNC_NICE now."
 49             ;;
 50     esac
 51     case "x$RSYNC_IONICE" in
 52     x-c[123]*)    RSYNC_IONICE_PARM="$RSYNC_IONICE";;
 53     x)        ;;
 54     *)        log_warning_msg "Value of RSYNC_IONICE in $RSYNC_DEFAULTS_FILE must be -c1, -c2 or -c3;"
 55             log_warning_msg "ignoring RSYNC_IONICE now."
 56             ;;
 57     esac
 58 fi
 59 
 60 export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
 61 
 62 rsync_start() {
 63     if [ ! -s "$RSYNC_CONFIG_FILE" ]; then
 64         log_failure_msg "missing or empty config file $RSYNC_CONFIG_FILE"
 65         log_end_msg 1
 66         exit 0
 67     fi
 68     # See ionice(1)
 69     if [ -n "$RSYNC_IONICE_PARM" ] && [ -x /usr/bin/ionice ] &&
 70         /usr/bin/ionice "$RSYNC_IONICE_PARM" true 2>/dev/null; then
 71         /usr/bin/ionice "$RSYNC_IONICE_PARM" -p$$ > /dev/null 2>&1
 72     fi
 73     if start-stop-daemon --start --quiet --background \
 74         --pidfile $RSYNC_PID_FILE --make-pidfile \
 75         $RSYNC_NICE_PARM --exec $DAEMON \
 76         -- --no-detach --daemon --config "$RSYNC_CONFIG_FILE" $RSYNC_OPTS
 77     then
 78         rc=0
 79         sleep 1
 80         if ! kill -0 $(cat $RSYNC_PID_FILE) >/dev/null 2>&1; then
 81             log_failure_msg "rsync daemon failed to start"
 82             rc=1
 83         fi
 84     else
 85         rc=1
 86     fi
 87     if [ $rc -eq 0 ]; then
 88         log_end_msg 0
 89     else
 90         log_end_msg 1
 91         rm -f $RSYNC_PID_FILE
 92     fi
 93 } # rsync_start
 94 
 95 
 96 case "$1" in
 97   start)
 98     if "$RSYNC_ENABLE"; then
 99         log_daemon_msg "Starting rsync daemon" "rsync"
100         if [ -s $RSYNC_PID_FILE ] && kill -0 $(cat $RSYNC_PID_FILE) >/dev/null 2>&1; then
101         log_progress_msg "apparently already running"
102         log_end_msg 0
103         exit 0
104         fi
105             rsync_start
106         else
107             if [ -s "$RSYNC_CONFIG_FILE" ]; then
108                 [ "$VERBOSE" != no ] && log_warning_msg "rsync daemon not enabled in $RSYNC_DEFAULTS_FILE, not starting..."
109             fi
110     fi
111     ;;
112   stop)
113     log_daemon_msg "Stopping rsync daemon" "rsync"
114     start-stop-daemon --stop --quiet --oknodo --pidfile $RSYNC_PID_FILE
115     log_end_msg $?
116     rm -f $RSYNC_PID_FILE
117     ;;
118 
119   reload|force-reload)
120     log_warning_msg "Reloading rsync daemon: not needed, as the daemon"
121     log_warning_msg "re-reads the config file whenever a client connects."
122     ;;
123 
124   restart)
125     set +e
126     if $RSYNC_ENABLE; then
127         log_daemon_msg "Restarting rsync daemon" "rsync"
128         if [ -s $RSYNC_PID_FILE ] && kill -0 $(cat $RSYNC_PID_FILE) >/dev/null 2>&1; then
129         start-stop-daemon --stop --quiet --oknodo --pidfile $RSYNC_PID_FILE || true
130         sleep 1
131         else
132         log_warning_msg "rsync daemon not running, attempting to start."
133             rm -f $RSYNC_PID_FILE
134         fi
135             rsync_start
136         else
137             if [ -s "$RSYNC_CONFIG_FILE" ]; then
138                 [ "$VERBOSE" != no ] && log_warning_msg "rsync daemon not enabled in $RSYNC_DEFAULTS_FILE, not starting..."
139             fi
140     fi
141     ;;
142 
143   status)
144     status_of_proc -p $RSYNC_PID_FILE "$DAEMON" rsync
145     exit $?    # notreached due to set -e
146     ;;
147   *)
148     echo "Usage: /etc/init.d/rsync {start|stop|reload|force-reload|restart|status}"
149     exit 1
150 esac
151 
152 exit 0
  1 #! /bin/sh
  2 
  3 ### BEGIN INIT INFO
  4 # Provides:          rsyncd
  5 # Required-Start:    $remote_fs $syslog
  6 # Required-Stop:     $remote_fs $syslog
  7 # Should-Start:      $named autofs
  8 # Default-Start:     2 3 4 5
  9 # Default-Stop:      
 10 # Short-Description: fast remote file copy program daemon
 11 # Description:       rsync is a program that allows files to be copied to and
 12 #                    from remote machines in much the same way as rcp.
 13 #                    This provides rsyncd daemon functionality.
 14 ### END INIT INFO
 15 
 16 set -e
 17 
 18 # /etc/init.d/rsync: start and stop the rsync daemon
 19 
 20 DAEMON=/usr/bin/rsync
 21 RSYNC_ENABLE=false
 22 RSYNC_OPTS=''
 23 RSYNC_DEFAULTS_FILE=/etc/default/rsync
 24 RSYNC_CONFIG_FILE=/etc/rsyncd.conf
 25 RSYNC_PID_FILE=/var/run/rsync.pid
 26 RSYNC_NICE_PARM=''
 27 RSYNC_IONICE_PARM=''
 28 
 29 test -x $DAEMON || exit 0
 30 
 31 . /lib/lsb/init-functions
 32 
 33 if [ -s $RSYNC_DEFAULTS_FILE ]; then
 34     . $RSYNC_DEFAULTS_FILE
 35     case "x$RSYNC_ENABLE" in
 36     xtrue|xfalse)    ;;
 37     xinetd)        exit 0
 38             ;;
 39     *)        log_failure_msg "Value of RSYNC_ENABLE in $RSYNC_DEFAULTS_FILE must be either 'true' or 'false';"
 40             log_failure_msg "not starting rsync daemon."
 41             exit 1
 42             ;;
 43     esac
 44     case "x$RSYNC_NICE" in
 45     x[0-9]|x1[0-9])    RSYNC_NICE_PARM="--nicelevel $RSYNC_NICE";;
 46     x)        ;;
 47     *)        log_warning_msg "Value of RSYNC_NICE in $RSYNC_DEFAULTS_FILE must be a value between 0 and 19 (inclusive);"
 48             log_warning_msg "ignoring RSYNC_NICE now."
 49             ;;
 50     esac
 51     case "x$RSYNC_IONICE" in
 52     x-c[123]*)    RSYNC_IONICE_PARM="$RSYNC_IONICE";;
 53     x)        ;;
 54     *)        log_warning_msg "Value of RSYNC_IONICE in $RSYNC_DEFAULTS_FILE must be -c1, -c2 or -c3;"
 55             log_warning_msg "ignoring RSYNC_IONICE now."
 56             ;;
 57     esac
 58 fi
 59 
 60 export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
 61 
 62 rsync_start() {
 63     if [ ! -s "$RSYNC_CONFIG_FILE" ]; then
 64         log_failure_msg "missing or empty config file $RSYNC_CONFIG_FILE"
 65         log_end_msg 1
 66         exit 0
 67     fi
 68     # See ionice(1)
 69     if [ -n "$RSYNC_IONICE_PARM" ] && [ -x /usr/bin/ionice ] &&
 70         /usr/bin/ionice "$RSYNC_IONICE_PARM" true 2>/dev/null; then
 71         /usr/bin/ionice "$RSYNC_IONICE_PARM" -p$$ > /dev/null 2>&1
 72     fi
 73     if start-stop-daemon --start --quiet --background \
 74         --pidfile $RSYNC_PID_FILE --make-pidfile \
 75         $RSYNC_NICE_PARM --exec $DAEMON \
 76         -- --no-detach --daemon --config "$RSYNC_CONFIG_FILE" $RSYNC_OPTS
 77     then
 78         rc=0
 79         sleep 1
 80         if ! kill -0 $(cat $RSYNC_PID_FILE) >/dev/null 2>&1; then
 81             log_failure_msg "rsync daemon failed to start"
 82             rc=1
 83         fi
 84     else
 85         rc=1
 86     fi
 87     if [ $rc -eq 0 ]; then
 88         log_end_msg 0
 89     else
 90         log_end_msg 1
 91         rm -f $RSYNC_PID_FILE
 92     fi
 93 } # rsync_start
 94 
 95 
 96 case "$1" in
 97   start)
 98     if "$RSYNC_ENABLE"; then
 99         log_daemon_msg "Starting rsync daemon" "rsync"
100         if [ -s $RSYNC_PID_FILE ] && kill -0 $(cat $RSYNC_PID_FILE) >/dev/null 2>&1; then
101         log_progress_msg "apparently already running"
102         log_end_msg 0
103         exit 0
104         fi
105             rsync_start
106         else
107             if [ -s "$RSYNC_CONFIG_FILE" ]; then
108                 [ "$VERBOSE" != no ] && log_warning_msg "rsync daemon not enabled in $RSYNC_DEFAULTS_FILE, not starting..."
109             fi
110     fi
111     ;;
112   stop)
113     log_daemon_msg "Stopping rsync daemon" "rsync"
114     start-stop-daemon --stop --quiet --oknodo --pidfile $RSYNC_PID_FILE
115     log_end_msg $?
116     rm -f $RSYNC_PID_FILE
117     ;;
118 
119   reload|force-reload)
120     log_warning_msg "Reloading rsync daemon: not needed, as the daemon"
121     log_warning_msg "re-reads the config file whenever a client connects."
122     ;;
123 
124   restart)
125     set +e
126     if $RSYNC_ENABLE; then
127         log_daemon_msg "Restarting rsync daemon" "rsync"
128         if [ -s $RSYNC_PID_FILE ] && kill -0 $(cat $RSYNC_PID_FILE) >/dev/null 2>&1; then
129         start-stop-daemon --stop --quiet --oknodo --pidfile $RSYNC_PID_FILE || true
130         sleep 1
131         else
132         log_warning_msg "rsync daemon not running, attempting to start."
133             rm -f $RSYNC_PID_FILE
134         fi
135             rsync_start
136         else
137             if [ -s "$RSYNC_CONFIG_FILE" ]; then
138                 [ "$VERBOSE" != no ] && log_warning_msg "rsync daemon not enabled in $RSYNC_DEFAULTS_FILE, not starting..."
139             fi
140     fi
141     ;;
142 
143   status)
144     status_of_proc -p $RSYNC_PID_FILE "$DAEMON" rsync
145     exit $?    # notreached due to set -e
146     ;;
147   *)
148     echo "Usage: /etc/init.d/rsync {start|stop|reload|force-reload|restart|status}"
149     exit 1
150 esac
151 
152 exit 0

View Code

View Code

 

 

 

 



开机自动运营rsync

开机自动运维rsync

  1. 扔脚本进去/etc/init.d/
  1. 扔脚本进去/etc/init.d/
  1. 授权
    chmod +x rsync
  1. 授权
    chmod +x rsync
  1. 若是抛出:binsh^M错误就举行编码改写
    安装dos统一编码
    (请看rsync脚本抛出binsh^M bad interpreter文书档案)
  1. 如若抛出:binsh^M错误就实行编码改写
    安装dos统一编码
    (请看rsync脚本抛出binsh^M bad interpreter文书档案)
  1. 累加到劳动
    chkconfig –add ningx
  1. 美高梅手机版4858,增加到劳动
    chkconfig –add ningx
  1. 随意运转脚本拉动rsync开机运营
    chkconfig –level 2345 rsync on
  1. 随便运转脚本推动rsync开机运维
    chkconfig –level 2345 rsync on

 

 

 

 



 

 

实施脚本时发现如下错误:
/bin/sh^M: bad interpreter: 未有至极文件或目录

实施脚本时发现如下错误:
/bin/sh^M: bad interpreter: 未有分外文件或目录

谬误分析:
因为操作系统是windows,笔者在windows下编写制定的脚本,所以有相当的大希望有不可知字符。
本子文件是DOS格式的, 即每1行的行尾以\n\r来标记, 其ASCII码分别是0x0D,
0x0A.

荒唐分析:
因为操作系统是windows,小编在windows下编写制定的脚本,所以有异常的大可能有不可知字符。
本子文件是DOS格式的, 即每一行的行尾以\n\r来标记, 其ASCII码分别是0x0D,
0x0A.

能够有很三种措施看那么些文件是DOS格式的依旧UNIX格式的, 依然MAC格式的

能够有很各种主意看那个文件是DOS格式的依旧UNIX格式的, 依旧MAC格式的

缓解形式:
vim filename
下一场用命令
:set ff? #能够看来dos或unix的字样. 假若真的是dos格式的。

杀鸡取卵办法:
vim filename
接下来用命令
:set ff? #能够看到dos或unix的字样. 要是的确是dos格式的。

然后用
:set ff=unix #把它强制为unix格式的, 然后存盘退出。
重复运维脚本。

然后用
:set ff=unix #把它强制为unix格式的, 然后存盘退出。
再度运营脚本。

 

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图
Copyright @ 2010-2019 美高梅手机版4858 版权所有