2014-01-21 6 views
0

Prod 서버에 로그인하여 파일을 찾고이를 StandBy 서버에 복사하는 스크립트를 작성했습니다.find : -exec와 함께 -exec에 인수가 없습니다. scp {}

내 스크립트입니다 :

find: missing argument to `-exec' 

내가 모든 문서 또는 \ '} {'넣어 말하던 보았다;

# ! /bin/ksh 

ssh -l oracle -p 20022 IP_Address "find /opt/oracle/wcm/backup/export/ -name "*.DMP" -mtime -1 -exec scp {} [email protected]_Address:/opt/oracle/wcm/impdumps" 

스크립트 내가 무엇입니까를 실행 한 후 줄의 끝에 있지만 아무것도 작동하지 않습니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?

답변

0

-exec을 이스케이프 처리 된 명령 구분자로 끝내야합니다. the manual에서 :

당신이 작동해야 무슨 일을하는지
-exec command ; 
      Execute command; true if 0 status is returned. All following 
      arguments to find are taken to be arguments to the command until 
      an argument consisting of ‘;’ is encountered. The string ‘{}’ 
      is replaced by the current file name being processed everywhere 
      it occurs in the arguments to the command, not just in arguments 
      where it is alone, as in some versions of find. Both of these 
      constructions might need to be escaped (with a ‘\’) or quoted to 
      protect them from expansion by the shell. 

; 당신은 당신이 '행의 끝에서 \;'를 넣어 시도 것 제안하지만, 전체 결합 된 명령 문자열의 끝을했다면 그것은 분명하지 않다 :

ssh ... "find ..." \; 

일을하고 여전히 것없는 것이다 '누락 된 인수'오류; 또는 인용 명령을 내 find 명령, 즉의 끝에서 당신은 ssh에 인수로 전달되고 있습니다

ssh ... "find ... \;" 

또한 쉘 확장이 개 가능한 레이어를 가지고있다. \;은 로컬 쉘에 의해 확장되므로 원격 쉘은 이것을 단지 ;으로 볼 수 있습니다. 당신은 그것을 두 번 탈출해야 할 수도 있습니다.

또한 파일 이름 패턴을 따옴표로 이스케이프해야합니다.

ssh -l oracle -p 20022 IP_Address "find /opt/oracle/wcm/backup/export/ -name \"*.DMP\" -mtime -1 -exec scp {} [email protected]_Address:/opt/oracle/wcm/impdumps \\;" 

당신은 간단하게 원격으로하기보다는 자극 서버에 직접 명령을 실행 찾을 수 있습니다,하지만 난 당신이 그렇게 선택하는 이유 아무 생각이 없다 이 작업을 정기적으로 수행하는 경우 생산성이 높은 서버에서 로컬로 rsync을 실행하십시오. find을 고수하면 설명서에 보안 문제에 대한 경고가 표시되고 -execdir을 사용하는 것이 좋습니다.

관련 문제