사이트 내 전체검색
[linux] [shell] 사용자별 디스트 사용 용량 체크 하기
로빈아빠
https://cmd.kr/server/310 URL이 복사되었습니다.

본문

[shell] 사용자별 디스트 사용 용량 체크 하기
 
#!/bin/sh CUID=500 CHECK=`cat /etc/passwd | sed -e 's/::/:nothing:/g' | sed -e 's/ //g' | sed -e 's /:/ /g' | awk '{print $6}'` if [ "$CHECK" != "" ]; then for i in $CHECK; do UIDS=`cat /etc/passwd | grep $i | sed -e 's/::/:nothing:/g' | sed -e 's/  //g' | sed -e 's/:/ /g' | awk '{print $3}'` UIDS=`echo $UIDS | sed -e 's/ /00000000/g'` if [ "$UIDS" -ge "$CUID" ] && [ "$UIDS" -lt 1000000 ]; then du -sh $i >> /tmp/du_result.txt fi done echo "space bar를 누르면 다음페이지를, q를 누르면 종료가 됩니다." echo "" cat /tmp/du_result.txt | less rm -rf /tmp/du_result.txt fi
김정균씨가 만드신 스크립트 입니다.

제 서버에서 실행한 결과를 보면 이렇습니다.

[root@localhost scripts]# ./du.sh
space bar를 누르면 다음페이지를, q를 누르면 종료가 됩니다.

1.6G    /home/ForSpeed
120k    /home/korea
124M    /home/minsu
4.0M    /home/sojung
1.5M    /home/coolamp
26M    /home/deny
3.4M    /home/ann
122M    /home/gury
123M    /home/jinmi
264k    /home/cool9
11M    /home/demons
188k    /home/butterfly
540k    /home/crash
336k    /home/cjy21
292k    /home/khaze
[root@localhost scripts]#

처음에 바로 받아서 실행 해 보니 제대루 돌아 가지 않아서 간단하게 디버그 했습니다.
이 소스를 처음 주신 동기 형에게 감사 드립니다. 유용하게 쓸수 있을것 같네요...

그런데 유져 별로 사용량을 체크 한다고 했는데 저건 디렉 터리로 나와서 제가 한줄 바꿔 봤
습니다.

#!/bin/bash CUID=500 CHECK=`cat /etc/passwd | sed -e 's/::/:nothing:/g' | sed -e 's/ //g' | sed -e 's /:/ /g' | awk '{print $6}'` if [ "$CHECK" != "" ]; then for i in $CHECK; do UIDS=`cat /etc/passwd | grep $i | sed -e 's/::/:nothing:/g' | sed -e 's/  //g' | sed -e 's/:/ /g' | awk '{print $3}'` UIDS=`echo $UIDS | sed -e 's/ /00000000/g'` if [ "$UIDS" -ge "$CUID" ] && [ "$UIDS" -lt 1000000 ]; then du -sh $i >> /tmp/du_result.txt fi done echo "space bar를 누르면 다음페이지를, q를 누르면 종료가 됩니다." echo "" cat /tmp/du_result.txt | sed -e 's/\/home\///g' | less #rm -rf /tmp/du_result.txt fi
우선 결과를 보면

[root@localhost /tmp]# /etc/scripts/du.sh
space bar를 누르면 다음페이지를, q를 누르면 종료가 됩니다.

1.6G    ForSpeed
120k    korea
124M    minsu
4.0M    sojung
1.5M    coolamp
26M    deny
3.4M    ann
122M    gury
123M    jinmi
264k    cool9
11M    demons
188k    butterfly
540k    crash
336k    cjy21
292k    khaze
[root@localhost /tmp]#

쪼금더 깔끔해 졌죠? ^^
간단 하지만 무지 유용한것 같네요^^

댓글목록

등록된 댓글이 없습니다.

1,139 (10/23P)

Search

Copyright © Cmd 명령어 3.142.173.1