check if file exists on remote host with ssh

后端 未结 11 716
醉酒成梦
醉酒成梦 2021-01-31 03:20

I would like to check if a certain file exists on the remote host. I tried this:

$ if [ ssh user@localhost -p 19999 -e /home/user/Dropbox/path/Research_and_Devel         


        
11条回答
  •  一生所求
    2021-01-31 03:23

    I wanted also to check if a remote file exist but with RSH. I have tried the previous solutions but they didn't work with RSH.

    Finally, I did I short function which works fine:

    function existRemoteFile ()
    {
    REMOTE=$1
    FILE=$2
    RESULT=$(rsh -l user $REMOTE  "test -e $FILE && echo \"0\" || echo \"1\"")
    if [ $RESULT -eq 0 ]
    then
        return 0
    else
        return 1
    fi
    }
    

提交回复
热议问题