[쉘 스크립트] du를 이용한 디렉토리 크기 구하는것 문의
글쓴이: ohsono / 작성시간: 일, 2007/12/09 - 8:27오후
유저별 디렉토리 사이즈 구하려고 하는데요
조건은 이렇습니다.
커맨드라인변수사용,알파벳순서로 정렬해서 출력, du -s 디렉토리이름,
유저이름(디렉토리)가 없을시 no such user화면출력후 입력 유저 순서대로 출력.
대강 제가 해본건 여기까진데. 아직 변수 하나 밖에 못했습니다. 정렬은 어떻해야할지
고수님들 도와주세요 ㅠㅠ +
저같은 경우 path설정하는법을 잘몰라서 입력시 ~유저 이런식으로 받게 했는데. 유저이름만 받을때 더 좋은방법은 없을지요?
(예, ~hogong 또는 /home)
#!/bin/csh -f
echo "DU: Show disk space"
## check if called properly
if($#argv != 1) then
echo "Usage: $0 ~username or $0 /path"
exit 1
endif
## save command line args in variables
set u1=$1
if (-e $u1) then
du -s $u1
else
echo "$u1 : no such user"
endif
Forums:
수정 소스코드
#!/bin/csh -f
##echo "DU: show disk space"
## check if called properly
if($#argv != 1) then
echo "WARNING: If you don't put argument, then it will just count the size of /home"
echo "[Usage: $0 ~username]"
du -s /home
exit 1
endif
sort /etc/passwd | awk '/home/' | awk -F: '{print FNR "\t" $1}' | tee user_list1
echo "CHECK: user_list1 file. you may see the list of users"
## save command line args in variables
set u1=$1
##set u2=$2
##set e1='egrep -s $u1 /home/cse411/hoson/user_list1'
if ( !'egrep -q $u1 user_list1ir' ) then
du -s $u1
else
echo "$u1 : no such user"
endif
여기 조건문에 username 을 받아서 user's home이 있는지 체크 하고 싶은데 어떻해 할지 감감합니다.
댓글 달기