사용자 도구

사이트 도구


os:linux:스크립트-모으자

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

다음 판
이전 판
os:linux:스크립트-모으자 [2012/10/26 14:55] – 바깥 편집 127.0.0.1os:linux:스크립트-모으자 [2024/04/23 22:44] (현재) – 바깥 편집 127.0.0.1
줄 1: 줄 1:
 +<title>스크립트를 모으자</title>
  
 +
 +**My du : 좀 더 보기 좋게**
 +<code bash>
 +#!/bin/sh
 +du -s -k $1 | awk '{print $1/1024" MB, original " $1 " Kb"}'
 +</code>
 +
 +**My ps : 좀 더 보기 좋게**
 +너무 오래된 코드라 그러나 잘 안되네.
 +<code bash>
 +#!/bin/sh 
 +ps -auxef | awk '
 +{ str i;
 +  if($3 > 1.00) { i = "\033[1;32m";
 +  else { i="";
 +  if($3 > 0.30) { printf ("%5.5d %s %2.2f %s %s %s \033[1;0m\n",$2,i,$3,$11,$12,$13); }
 +}' 
 +</code>
 +
 +**pu**
 +뭐지 기억이 안나네, 내가 실행한 프로세스 보는거든가.
 +<code bash>
 +#!/bin/sh
 +ps -aux | egrep '\!:1|PID'
 +</code>
 +
 +**kill : 대체물**
 +뭐가 좋은건지 기억 안남 ㅠ.ㅠ
 +<code bash>
 +#! /bin/sh
 +pid=`ps -e | grep -w $1 | sed -e 's/ *//' -e 's/ .*//'`
 +if [ "$pid" != "" ]; then
 +  kill -TERM $pid && echo "done" || echo "failed" > /dev/null
 +fi
 +</code>
 +
 +**chk_proc**
 +프로세스 살아 있는지 체크하는 것
 +<code bash>
 +#! /bin/sh
 +pid=`ps -e | grep -w $1 | sed -e 's/ *//' -e 's/ .*//'`
 +[ "$pid" != "" ] && exit 0 || exit 1
 +</code>
 +
 +**duConv : 파일명교체**
 +<code bash>
 +#!/bin/sh
 +mv $1 $1.tmp
 +duconv -u $1.tmp $1
 +rm -f $1.tmp
 +</code>
 +
 +**Run**
 +리눅스에서 프로세스 실행할때 썼던 거 같은데 쓰려면 하드코딩된 패스를 수정해서 써야함
 +<code bash>
 +#! /bin/sh
 +
 +#. /etc/rc.config ##It works only under suse linux
 +
 +## Formating the boot script messages, see /etc/rc.status.
 +## Source /etc/rc.status if rc_done isn't defined
 +##
 +test "$rc_done"= = = -a -e ~/bin/rc.status && . ~/bin/rc.status
 +
 +#script file name
 +#
 +base=${0##*/}
 +link=${base#*[SK][0-9][0-9]}
 +
 +#rc_done="done"
 +#rc_failed="failed"
 +
 +test $link = $base
 +return=$rc_done
 +
 +case "$2" in
 + start)
 + _chk_proc $1 && {
 + _kill $1 
 + echo -n "Re-"
 + }
 + echo -n "Starting $1 server"
 + { $1 & } || return=$rc_failed
 + echo -e "$return"
 + ;;
 +
 + stop)
 + _chk_proc $1 || {
 + echo -n "$1 not running"
 + echo -e "$rc_unused"
 + exit 1
 + }
 + echo -n "Shutting down $1 server"
 + _kill $1 || return=$rc_failed > /dev/null
 + echo -e "$return"
 + ;;
 +
 + restart)
 + $0 $1 stop && $0 $1 start || return=$rc_failed
 + ;;
 +
 + status)
 + _chk_proc $1 && echo "Run result : $1 running" || echo "Run result : $1 not running"
 + ;;
 + *)
 + echo "Usage: $0 ProgramName {start|stop|restart|status}"
 + exit 1
 +esac
 +test "$return" = "$rc_done" || exit 1
 +exit 0
 +</code>