How do I check to see if a file exists on a remote server using shell -
i have done lot of searching , can't seem find out how using shell script. basically, copying files down remote servers , want else if doesn't exist. have array below, tried reference directly, still returning false.
i brand new @ this, please kind :)
declare -a array1=('user1@user1.user.com'); in "${array1[@]}" if [ -f "$i:/home/user/directory/file" ]; stuff else other stuff fi done
assuming using scp , ssh remote connections should want.
declare -a array1=('user1@user1.user.com'); in "${array1[@]}"; if ssh -q "$i" "test -f /home/user/directory/file"; scp "$i:/home/user/directory/file" /local/path else echo 'could not access remote file.' fi done alternatively, if don't need care difference between remote file not existing , other possible scp errors following work.
declare -a array1=('user1@user1.user.com'); in "${array1[@]}"; if ! scp "$i:/home/user/directory/file" /local/path; echo 'remote file did not exist.' fi done
Comments
Post a Comment