简体   繁体   English

使用 rsync 在脚本上无限循环

[英]Infini loop on a script using rsync

I made a function using rsync copying file from rep1 to rep2.我使用 rsync 将文件从 rep1 复制到 rep2 做了一个函数。 I used getopt to create an argument calling this function.我使用 getopt 创建了一个调用此函数的参数。 The function is called in the case but doing an infinite loop, i don't know why.在这种情况下调用该函数但执行无限循环,我不知道为什么。 I tried this function without case and it worked nicely.我在没有大小写的情况下尝试了此功能,并且效果很好。

Stuff in rsync(): rsync() 中的内容:

    read -p 'Enter source directory : ' repSource
    read -p 'Enter destination directory : ' repDest


    if [ -e $repSource ] && [ -d $repSource ] && [ -e $repDest ] && [ -d $repDest ]
    then
            echo "File exists and it is a directory !"
            echo "Synchronisation of " $repSource "to " $repDest
            rsync -av $repSource  $repDest


    else

            echo "File doesn't exit or it is not a directory  !"
    fi

Here my case:这是我的情况:

OPTS=$(getopt -o h,m,p,a,l,t) 
if [ $? != 0 ]
then
    exit 1
fi

    case "$1" in

             -h) aide;
               exit 0;;
             -m) RAM;
               exit 0;;
             -p) CPU;
               exit 0;;
             -a) logcpu;
               exit 0;;
             -l) autolog;
               exit 0;;
             -t) rsync;
               exit 0;;
    esac

Here the result:结果如下:

Enter source directory : rep1/
Enter destination directory : rep2/
File exists and it is a directory !
Synchronisation of  rep1/ to  rep2/
Enter source directory :

Thanks for your help!谢谢你的帮助!

You are shadowing the "real" command rsync with your function of the same name.您正在使用同名函数隐藏“真实”命令rsync You can keep rsync as the function name, but then you need to use the built-in command to ignore the function and call the real command.您可以保留rsync作为函数名,但是您需要使用内置command来忽略该函数并调用真正的命令。

command rsync -av "$repSource" "$repDest"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM