2014-01-10 2 views
0

다음과 같은 셸 스크립트가 있습니다. 수동으로 실행하면 파일에 출력이 추가됩니다. crontab에서 스크립트를 실행하도록 예약하면 출력이 출력 파일에 추가되지 않습니다.sqlplus 쿼리는 셸 스크립트에서 실행할 때 결과를 파일에 저장하지 않습니다.

#!/bin/bash 
cd /home/sample 

echo "SELECT count (*) FROM Mytable;"| sqlplus -L user/[email protected] > sample.txt 

echo "SELECT name, age count(*) from mytable "| sqlplus -L lmsuser/[email protected] > sample1.txt 
+0

'crontab'의 내용은 무엇입니까? –

+0

57 * * * * /data/sample.sh >> /data/sample.log – user2306367

+0

쉘 스크립트 명령이나'/ data/sample '과 같이 출력 파일을'sample1.txt'로 보내야합니다. log'을 crontab과 같이 사용 하시겠습니까? 나는 당신이'/ data/sample.log'에서 기대하고있는 동안 출력이'sample1.txt'로 간다고 생각합니다. –

답변

0

사람이 볼 수있는 것과 연결되어 있지 않으므로 출력으로 재미있는 일을합니다.

cron then wakes up every minute, examining all stored crontabs, check- 
    ing each command to see if it should be run in the current minute. 
    When executing commands, any output is mailed to the owner of the 
    crontab (or to the user named in the MAILTO environment variable in the 
    crontab, if such exists). The children copies of cron running these 
    processes have their name coerced to uppercase, as will be seen in the 
    syslog and ps output. 

나는 어디에서 이것이 일어나는 지 모른다; 표준에 영향을 줄 수 있습니다.

출력을 리디렉션했는지 확인하려면 이메일을 확인하십시오.

0

나는이 동일한 문제에 직면했다. 이것은 보통 cron이 .profile에서 초기화 된 변수를 인식하지 못하기 때문에 발생합니다. 심지어 sqlplus 경로는 cron을 통해이 스크립트를 실행할 때 사용할 수 없습니다. 문제를 해결하려면 cron 작업을 아래 형식으로 설정하십시오. 그러면 제대로 작동합니다.

00 * * * * . ~/.profile && /home/absolut_path_to_script.sh > /home/log_file_path.txt 

P. 나는 그것을 사용했다. .profile 앞에로드하여 동일하게로드합니다. 그것은 내 문제를 해결하고, cron은 원하는 출력을 생산하고 있습니다.

관련 문제