您的位置:首页 > 其它

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

2016-09-22 17:30 1186 查看
有时候用scp复制文件到远程服务器时候会遇到远程的目录是否存在的问题

bash1

ssh $SERVER_IP "[ -d $FOLDER ]" >/dev/null 2>&1
if [ $? -ne 0 ]
then
#脚本不正常退出
exit 1
fi


# >/dev/null 2>&1将标准输出和错误输出定向到null,不输出


bash2

#!/bin/bash

ssh_host=$1
filePath=$2

if ssh $ssh_host test -e $filePath;
then echo $filePathexists
else echo $filePathdoes not exist
fi


测试
./test.sh 192.168.222.22 /temp
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: