'Shell Script'에 해당되는 글 2건

  1. 2010/12/21 파일명 일괄변경
  2. 2007/09/06 OpenVZ 대화식모드에서 guest system을 생성하는 쉘스크립트
#!/bin/sh

# 주의
# 바꿀 문자열의 디렉토리명도 바꾼다.
# 파일부터 바꾼다음 디렉토리를 바꾼다.
# find 로 검색한 결과를 순차적으로 바꾸면 나중에 나오는 파일은 못찾게 된다.

target_dir="/home/test"
target_files=`find "$target_dir" -type f`

from="old_name"
to="new_name"

# 파일을 바꾼다
for file in $target_files ; do

       # 순수 파일명 추출
       f=`basename $file`

       # 해당파일인지 판별후 변환
       if [ `echo $f | grep "$from"` ]; then
               tmp=`echo $f | sed "s/$from/$to/g"`

               new_file=`dirname ${file}`/${tmp}

               mv -f $file $new_file

               echo "change file : $file ===> $new_file "
       fi
done


# 디렉토리를 바꾼다
dir_file=`find "$target_dir" -type d`
for dir in $dir_file ; do
       # 해당 디렉토리인지 판별후 변환
       if [ `echo $dir | grep "$from"` ]; then
               new_dir=`echo $dir | sed "s/$from/$to/g"`

               mv -f $dir $new_dir
               echo "change dir : $dir ===> $new_dir "
       fi
done

exit 0
#!/bin/sh

# Maintainer    : gogisnim (gogisnim@gmail.com)
# Last Modify   : 2007.09.06
# Usage         : vps_make.sh
# Note          :
# This is tool OpenVZ create guest system on interactive.
# Check vzctl!. http://openvz.org
# This script must be installed dialog utility and root authority.

TEMPLATE="gentoo-2.6.18"
TMPFILE="/tmp/tmp.$$"
PRIVATE="/vz/private/"
FLAG=0

! which dialog > /dev/null 2>&1 && echo "ERROR: The dialog utility is required for vps_make.sh.  Exiting!" && exit 1

if [ "$USER" != "root" ]; then
   echo "ERROR: You must be root authority"
   exit 1
fi

umask 177
trap 'rm -f $TMPFILE; exit 1' EXIT INT

number_check() {
   if [ -z "$1" ]; then
       echo "usage: number_check num"
       exit 1
   fi 
   echo $1 | grep ^[[:digit:]]*$ > /dev/null 2>&1
   return $?
}


for no in `ls $PRIVATE`; do
   test "${num:-0}" -lt "$no" && num=$no
done
new_num=`expr $num + 1`

# VEID input and check
until false; do
   dialog --title "VEID" --inputbox "Please enter new VEID : " 20 60 $new_num 2> $TMPFILE
   VEID=`cat $TMPFILE`

   test -z "$VEID" && FLAG=1 && continue
   for no in `ls $PRIVATE`; do
       FLAG=0
       test "$VEID" -eq "$no" && FLAG=1 && break
   done
   number_check $VEID || FLAG=1

   test "$FLAG" = "0" && break
done

# hostname input
dialog --title "hostname" --inputbox "Please enter new hostname : " 20 60 "vps$VEID" 2> $TMPFILE
HOSTNAME=`cat $TMPFILE`

# IP address input
dialog --title "IP Address" --inputbox "Please enter IP : " 20 60 "192.168.0.1" 2> $TMPFILE
IP=`cat $TMPFILE`

# nameserver input
dialog --title "nameserver" --inputbox "Please enter nameserver : " 20 60 "168.126.63.1" 2> $TMPFILE
NAMESERVER=`cat $TMPFILE`

# onboot yes/no
dialog --title "onbook option" --menu "VEID $VEID active on boot time" 20 60 2 yes "Yes, I'll be active vps on boot" no "No, unactive" 2> $TMPFILE
ONBOOT=`cat $TMPFILE`

dialog --title "Information" --msgbox "System is ready to make VPS $VEID...\n\nVEID : $VEID\nHostname : $HOSTNAME\nIP Address : $IP\nNameserver : $NAMESERVER\nOn Boot : $ONBOOT" 20 60

vzctl create $VEID --ostemplate $TEMPLATE &&
vzctl set $VEID --save --onboot=$ONBOOT --ipadd $IP --nameserver $NAMESERVER --hostname $HOSTNAME

exit 0

사용자 삽입 이미지