쉘 스크립트 파일 읽어들이기
글쓴이: ng4you / 작성시간: 수, 2014/06/18 - 10:50오전
쉘 스크립트 초보자입니다.
쉘 스크립트를 이용하여 간단한 툴을 만들고 있습니다.
아래와 같이 테스트 해본결과 정상적으로 동작하더군요
while read line;
do
scp heejun86.kang@10.168.177.123:~/$line .
done < test.txt
그런데 위에 디렉토리 생성과 변경 커맨드를 적으면
test.txt를 찾지 못한다고 실행메시지가 발생합니다. 이렇게요
mkdir gathered_files
cd gathered_files
while read line;
do
scp heejun86.kang@10.168.177.123:~/$line .
done < test.txt
mkdir: cannot create directory `gathered_files': File exists
./scp.sh: line 18: test.txt: No such file or directory
쉘 스크립트 syntax를 잘 몰라서 위에 쓴 커맨드가 아래 소스에 영향을 미치는것 같은데
어떤것 때문에 이런 경우가 생기는 것인가요?
Forums:
d
cd gathered_files
이 라인이 문제가 되는듯 하네요.
위 스크립트와 아래스크립트의 차이를 보면 test.txt 를 읽을 때 경로가 다르게 되는데요.
스크립트 경로가 /home/temp 라고 가정하면 첫번째의 경우 /home/temp/test.txt 파일을 읽게 되고 아래의 경우 /home/temp/gather_files/test.txt 파일을 읽게 됩니다.
(스크립트를 crontab 으로 실행하면 작업 경로는 달라집니다.)
test.txt 파일이 어느 경로에 존재하는지 확인이 필요할 것 같습니다.
감사합니다.
directory가 변경이 되어서 그렇군요 ㅎㅎ 감사합니다~!
댓글 달기