728x90
반응형

오랜만에 지식인 답글 놀이를 하는데.. AIX 5.2에-mmin 옵션이 없다는 내용을 보았다.

오잉? AIX 5.2에 -mmin 옵션이 없어? 구글링으로 살펴보니 정말 5.2에 없으니 다른 방안을 알려달라는 글들이 보인다.

===============================================================================================

http://serverfault.com/questions/373545/how-to-tell-if-a-file-is-older-than-30-minutes-on-aix

I'd like to write a shell script in ksh or bash which exits with 1 if a specific file is older than 30 minutes. (Last modification time is older than half hour). It would be easy on a Linux or a modern unix, but I have to do it on AIX 5.2 version.

So the constraints:

  • there is no -mmin -mmax options in 'find'
  • there is no -d option in touch (touch -d '30 minutes ago' temp then find ! -newer temp doesn't work)
  • there is no 'stat' command
  • there is no %s parameter in the 'date' command (date +%s doesn't work)
  • I'm not allowed to install any software

Could you please help how can I do it with these constraints?

==============================================================================================

지식인에 올라온 글도 비슷한 맥락의 글로 "오라클 아카이브 파일이 너무많아서 5시간 지난것은 찾아서 지우게 하고 싶다라는게 질문의 요지였다.

이에 구글링에서 찾은 글에 달린 답글들을 보고 스크립트를 짬뽕하였는데 .. 아래와 같이 만들었다.

 

1. 특정 파일을 현재시간 -5가 되게 생성하고 TZ(time zone 옵션으로 가능)

    # touch -t `TZ=-04:00 date '+%Y%m%d%H%M.%S'` file2  <-- -t TZ로 가능하더이다)

2. ls 로 받은 파일 리스트랑 해당 파일을 비교하여 (파일1 -nt 파일2)

3.  파일1 보다 오래된 것을 넘겨 받아서 rm -f 로 지운다.

===============================================================================================

요지만 이렇고 스크립트는 간단하게 1,2,3에 맞춰서 정말 단순하게 만들었다. 지식인 답글달려는건데 복잡하게 할것도 없고 요지만(1,2,3) 잡아주면 되니까.. (사실 제대로 만들 실력도 안된다.)

#/bin/bash

 

FILELIST=`ls`

touch -t `TZ=-04:00 date '+%Y%m%d%H%M.%S'` file2 

FILESRC="file2"

 

for f in $FILELIST; do

echo $f

if [ $FILESRC -nt $f ]; then

rm -f $f

fi

rm file2

done

 

아 부끄러울 정도로 단순하다 ㅡㅡ;

================================================================================================

AIX 5.2에서 고민하시는 분들을위해.. 기록만..

728x90
반응형
블로그 이미지

nineDeveloper

안녕하세요 현직 개발자 입니다 ~ 빠르게 변화하는 세상에 뒤쳐지지 않도록 우리모두 열심히 공부합시다 ~! 개발공부는 넘나 재미있는 것~!

,