Unison+inotify做双向同步,脚本开机运行但数据没有同步,请高手帮忙指导。
我做了Unison+inotify双向同步,脚本文件位置:/root/inotify.sh。脚本内容
#/bin/bash
ip2="172.30.1.23"
src2="/home/wwwroot/discuz/"
dst2="/home/wwwroot/discuz/"
/usr/local/bin/inotifywait -mrq -e create,delete,modify,move $src2 | while read line
do
/usr/local/bin/unison -batch $src2 ssh://$ip2/$dst2
echo -n "$line " >> /var/log/inotify.log
echo `date | cut -d " " -f1-4` >> /var/log/inotify.log
done
设置了开机启动
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
bash /root/inotify.sh
开机后也看到有这个脚本在运行了
# ps aux | grep inotify.sh
root 14750.00.1 51201240 ? S 15:19 0:00 bash /root/inotify.sh
root 14770.00.0 5120 452 ? S 15:19 0:00 bash /root/inotify.sh
root 15040.00.0 4356 732 pts/1 S+ 15:19 0:00 grep inotify.sh
但是当一台主机更新数据之后,另一个主机没有反映。
我直接在当前运行sh /root/inotify.sh的时候主机执行后就可以同步了。请问各位大侠有没有别的办法让他设置成开机脚本就能起作用啊? 把sh /root/inotify.sh写入到/etc/rc.local看行不行 /bin/sh /root/inotify.sh sky 发表于 2015-9-18 15:42
/bin/sh /root/inotify.sh
嗯,我直接在rc.local里写的sh /root/inotify.sh我去加上/bin试试。
sky 发表于 2015-9-18 15:42
/bin/sh /root/inotify.sh
不行啊,亲。重启了以后显示这个脚本是在运行的
# ps aux | grep inotify.sh
root 14590.00.1 51201244 ? S 15:45 0:00 /bin/sh /root/inotify.sh
root 14610.00.0 5124 788 ? S 15:45 0:00 /bin/sh /root/inotify.sh
root 15090.00.0 4356 732 pts/2 S+ 15:46 0:00 grep inotify.sh
可是我改了一台主机的数据,另一台主机还是同步不了
看看开机启动日志是不是有报错呢 sky 发表于 2015-9-18 16:21
看看开机启动日志是不是有报错呢
日志里没有报错的地方。
开机用ps aux查显示的是root 14660.00.1 51201240 ? S 16:24 0:00 /bin/sh /root/inotify.sh
root 14670.00.0 2348 652 ? S 16:24 0:00 /usr/local/bin/inotifywait -mrq -e create,delete,modify,move
root 14680.00.0 5120 456 ? S 16:24 0:00 /bin/sh /root/inotify.sh
麻烦你看一下这个是不是正常的
sky 发表于 2015-9-18 16:21
看看开机启动日志是不是有报错呢
这是开机启运时的状态
root 14660.00.1 51201240 ? S 16:24 0:00 /bin/sh /root/inotify.sh
root 14670.00.0 2348 652 ? S 16:24 0:00 /usr/local/bin/inotifywait -mrq -e create,delete,modify,move
root 14680.00.0 5120 456 ? S 16:24 0:00 /bin/sh /root/inotify.sh
这是我手动运行的状态
root 14990.00.1 50601160 pts/0 S+ 17:04 0:00 bash /root/inotify.sh
root 15000.50.0 2260 632 pts/0 S+ 17:04 0:00 /usr/local/bin/inotifywait -mrq -e crea
root 15010.00.0 5060 452 pts/0 S+ 17:04 0:00 bash /root/inotify.sh
START项一个是S,一个是S+,是不是问题就出在这里?能解决吗?
开机改成这样试试bash /root/inotify.sh 最好带上全路径 sky 发表于 2015-9-18 20:33
最好带上全路径
现在两台主机,一台是/bin/sh /root/inotify.sh;一台是/bin/bash /root/inotify.sh;都不起作用,开机以后的START状态都是S。
状态在S的时候脚本是不起作用的,但是我手动运行脚本之后,界面的命令行就没有了,需要再另开一个SSH才能操用,状态也变成了S+。 sky 发表于 2015-9-18 16:21
看看开机启动日志是不是有报错呢
亲,我发现错误了,重启之后一开始我以为是卡到那里进不去了,其实脚本是在运行了,但是我去更改监视文夹件的文件的时候,他出报错。
页:
[1]