2013년 8월 5일 월요일

crontab 사용 및 배치 스크립트

배치 스크립트 예제: http://www.lucasward.net/2010/07/spring-batch-deployment-example.html
#!/bin/bash

CP=실행할xml이있는폴더/

LIB=프로젝트의라이브러리들이있는폴더/*
for f in $LIB
do
CP=$CP:$f
done

java -cp $CP org.springframework.batch.core.launch.support.CommandLineJobRunner \
예제잡파일.xml 예제잡이름

크론탭 사용 예제: http://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/
* * * * * command to be executed
- - - - -
| | | | |
| | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)

XML 파일에 스크립트를 삽입시켜 사용할 수 있다.
 <hdp:script id="adSetUp" language="javascript" run-at-startup="false">
     //importPackage(java.util);
     
     inputPath = "/로컬파일주소"
     outputPath="/hdfs로 복사할 주소"
     if(fsh.test(outputPath)) {
      fsh.rmr("file://".concat(outputPath))
     }
     if(fsh.test(inputPath)) {
      fsh.get(inputPath,outputPath)
       }
   </hdp:script>
이 스크립트는 스크립트 id를 job id처럼 호출 하면 된다. 혹은 run-at-startup 항목을 true로 하면 자동 실행된다.

댓글 없음:

댓글 쓰기