判断远程主机上的目录是否存在

来源:互联网 发布:淘宝创业失败案例 编辑:程序博客网 时间:2024/06/08 17:28

有时候用scp复制文件到远程服务器时候会遇到远程的目录是否存在的问题

bash1

ssh $SERVER_IP "[ -d $FOLDER ]" >/dev/null 2>&1if [ $? -ne 0 ]then   #脚本不正常退出    exit 1fi
# >/dev/null 2>&1将标准输出和错误输出定向到null,不输出

bash2

#!/bin/bashssh_host=$1filePath=$2if ssh $ssh_host test -e $filePath;    then echo $filePathexists    else echo $filePathdoes not existfi

测试 ./test.sh 192.168.222.22 /temp

0 0
原创粉丝点击