필자는 bash를 사용하여 스크립팅의 세계를 연구하기 시작했고 외부 플래시의 백업 위치에 하위 폴더가 들어있는 폴더의 내용을 복사하는 간단한 스크립트를 작성하려고합니다. 드라이브 (Thunderbird의 데이터를 백업하려고 시도). 몇 가지 자습서를 살펴본 결과, 스크립트에서 상위 디렉토리로 이동하는 방법에 대한 문제가 있습니다. 복사하려는 폴더가 스크립트 파일이있는 위의 디렉토리 1에 있습니다. 내가 백업 업을하는 두 개의 상위 디렉토리를 통해 ... 여기있어 하드 드라이브에 도착하려면 내가 만든거야 (I 우분투를 12.04를 실행 해요) :이 프로그램을 실행할 때Bash 스크립트 : 디렉토리를 외장 드라이브에 복사 - 디렉토리를 탐색하는 방법?
#! /bin/bash
#this attepmts to copy the profile folder for Thunderbird to the backup drive
echo "...attempting to copy Thunderbird Profile to back-up drive (My Passport)"
#attempt to backup two directories to where media folder (and therefore My Passport is located)
parent=$(dirname $PWD)
grandparent=$(dirname $parent)
greatgrand=$(dirname $grandparent)
#show what directories the variables are set to
echo "...parent: $parent"
echo "...grandparent: $grandparent"
echo "...greatgrand: $greatgrand"
echo "...copying..."
#FIRST SUBSHELL
#create a subshell and cd to directory to copy && tar directory
#tar: -c = create tarball, -f = tells it what to create " - " = is the unix convention for stdout (this goes with the -f) " . " = means the whole directory. I the end this first subshell is creating a tarball and dumping it in stdout
# | = pipe
#SECOND SUBSHELL
(cd /mcp/.thunderbird/lOdhn9gd.default && tar -cf - .) | (cd $greatgrand/media/My Passport/Gmail_to_Thunderbird_Backup && tar -xpf -)
내가 얻을 :
[email protected]:~/BashScriptPractice$ ./thunderProfileBU.sh
...attempting to copy Thunderbird Profile to back-up drive (My Passport)
...parent: /home/mcp
...grandparent: /home
...greatgrand:/
...copying...
./thunderProfileBU.sh: line 23: cd: //media/My: No such file or directory
./thunderProfileBU.sh: line 23: cd: /mcp/.thunderbird/lOdhn9gd.default: No such file or directory
"/ mcp"디렉토리에서 시작해야합니다. 위의 첫 번째 하위 스크립트 (마지막 줄)에서 필요하지 않다고 추측하고 있지만 "cd /.thunderbird/lOdhn9g ..."를 사용하려고했을 때 오류가 계속 발생했습니다. 두 번째 하위 스크립트에서 나는 어떤 일이 일어나고 있는지 정확히 알지 못합니다. 폴더 탐색 구문을 잘못 이해하고 있습니까?
또한 이것은 부차적 인 질문이지만 소프트웨어 개발자가해야 할 일을 알고 있거나 시스템 관리자에게 더 많은 일을하도록하는 방식으로 스크립팅하고 있습니까? 어떤 스크립팅 수업도 듣지 못했거나 대학을 통해 제공되는 것을 알고 있지만 흥미롭고 유용한 방법을 알 수 있습니다 ... 감사합니다!
있습니까? –
rsync에 익숙하지 않습니다. 그게 bash 유틸리티인가요? 편집 : 그냥 그것을 보았다. 매우 흥미로운. 나는 스크립트를 통해 그것을 구현하는 데 흥미로울 것이다. 비록 내가 여전히 다른 디렉토리를 탐색하는 데 문제가 있을지 모르지만 ... – MCP
스크립트 상단에'set -x'를 넣으면 각 명령을 출력 할 수있다. 실행되고 확장되며 디버깅 할 때 큰 도움이 될 수 있습니다. 완료되면 꺼내십시오. – meowsqueak