.png)
이를 통해 다음을 cp
수행할 수 있습니다.
$ mkdir q
$ touch s
$ cp -T s q # I need same effect with scp and/or rsync.
cp: cannot overwrite directory 'q' with non-directory
$ ls q
scp
하나의 명령으로 동일한 효과를 사용하거나 얻는 방법은 무엇입니까 rsync
? 즉, 대상이 디렉터리인 경우 실제 파일 전송이 필요 없이 0이 아닌 종료 코드로 종료되기를 원합니다. 나는 s
파일을 디렉토리에 넣고 싶지 않습니다 q
.
물론 개별적으로도 확인할 수 있습니다. 문제는 하나의 명령으로 이를 수행하는 방법입니다. 특히 동시성의 경우.
답변1
문제의 원격 디렉터리가 존재하면 중단됩니다.
if ! ssh user@host "[[ -d /path/to/directory ]]"; then
# do your scp or rsync
else
echo "Remote location is a directory. Aborting." 1&>2
exit 1
fi
이를 선으로 바꾸려면 다음을 수행하십시오.
ssh user@host "[[ -d /path/to/directory ]]" || <<scp or rsync>>
답변2
옵션:
ssh remote-server 'cat > /tmp/asd' < /tmp/qwe
하지만 매개변수는 아닙니다.
예:
$ ssh localhost 'cat > /tmp/oi' < /tmp/qwe ; echo $?
Authenticated to localhost ([::1]:22).
bash: /tmp/oi: Is a directory
Transferred: sent 2832, received 2548 bytes, in 0.0 seconds
Bytes per second: sent 60414.8, received 54356.2
1
$ ssh localhost 'cat > /tmp/asd' < /tmp/qwe ; echo $?
Authenticated to localhost ([::1]:22).
Transferred: sent 2832, received 2496 bytes, in 0.0 seconds
Bytes per second: sent 62499.8, received 55084.5
0
$ ls -l /tmp/{qwe,asd,oi}
-rw-r--r-- 1 george george 4 Apr 19 21:21 /tmp/asd
-rw-r--r-- 1 george george 4 Apr 19 21:19 /tmp/qwe
/tmp/oi:
total 0