脚本应用问题,求大佬!!!!!!!!!!!

我在openeuler下写了一个rsync和inotify的脚本。内容如下:
#!/bin/bash
INOTIFY=“inotifywait -mrq -e modify,create,attrib,move,delete /mnt”
RSYNC=“rsync -rav --delete --no-perms /mnt/ xxx@192.168.1.11:/srv/dev-disk-by-uuid-5eef9e”
$INOTIFY | while read DIRECTORY EVENT FILE
do
if [ $(pgrep rsync | wc -l) -le 0 ];then
$RSYNC
fi
done

写完后,脚本能正常运行,数据也能正常同步。
但是重启服务器后,脚本无法运行,手动启动脚本也没反应。
请问这是什么原因?

sh -x 执行脚本,调试看看;或者命令逐条跑一下,看看哪里有报错

考虑下使用sersync替代rsync+inotify

试着在要执行的地方加上大括号,另外命令用绝对路径,试下下面的脚本:

#!/bin/bash
INOTIFY="inotifywait -mrq -e modify,create,attrib,move,delete /mnt"
RSYNC="rsync -rav --delete --no-perms /mnt/ xxx@192.168.1.11:/srv/dev-disk-by-uuid-5eef9e"

${INOTIFY} | while read DIRECTORY EVENT FILE
do
    if [ $(pgrep rsync | wc -l) -le 0 ]; then
        ${RSYNC}
    fi
done

如果还不行的话,就单步调试下,看哪个地方错误

单步调试是对的,执行脚本就没反应。

System D 启动试试?