shell 을 통해서 특정파일을 0 bytes 로 바꾸기. - log 초기화하기등.
몇가지의 shell 명령어만 알면 쉽게 만들어서 활용할수 있다.

사례) ProFrame 의 서버로그를 0 Bytes 로 모두 초기화하기.
#!/usr/bin/ksh

if [ `hostname` != "ap" ]; // if 를 통해 hostname 을 확인한다.
then
    echo " Please... hostname check "
    exit 1  
fi

for file in `ls /log/*.log` // for 를 통해 디렉토리 파일개수만큼 돌면서 > 한다.
do
    echo "$file -> 0 bytes"
    > $file 
done

df -k /log // size 를 확인해본다. 개인적으로 bdf 를 더 선호함.

exit 0


역시 man 명령어는 모든걸 포함하고 있다.乃

$man ksh
  
@ if 
if list then list [ elif list then list] ... [ else list] fi
                     The list following if is executed and, if it returns a
                     zero exit status, the list following the first then is
                     executed.  Otherwise, the list following elif is
                     executed and, if its value is zero, the list following
                     the next then is executed.  Failing that, the else list
                     is executed.  If no else list or then list is executed,
                     if returns a zero exit status

@ for 
for identifier [in word ...] do list done
                     Each time for is executed, identifier is set to the
                     next word taken from the in word list.  If in word ...
                     is omitted, for executes the do list once for each
                     positional parameter set (see Parameter Substitution
                     below).  Execution ends when there are no more words in
                     the list.





'Computer Science > UNIX' 카테고리의 다른 글

Find 명령어로 파일갯수 찾기.  (0) 2014.03.15
UNiX : HTOP is a better TOP.  (0) 2011.09.29
UNIX - Shell 어제 날짜 구하기  (0) 2009.05.29
UNIX grep 옵션 -v 설명  (0) 2009.05.28
UNIX - ln (link files and directories)  (0) 2009.05.06
페이스북 댓글
티스토리 댓글

+ Recent posts