제목은 거창한데(?) 별거 아닌 스크립트입니다. 전에 제가 제 리눅스머신에서
그룹을 새로 만들면서 뭘 잘못 했었는지, 아니면 크래커가 들어 와었던지 간에
제 홈에 있는 파일을, 디렉토리들의 소유권이 이상하게 바뀌어 있어서 일일이
바꾸는게 귀찮고 짜증이 나서 아래 스크립트를 만들게 됐습니다. 혹 저같은
경우를 당한 사람이 있으면 도움이 되라고 여기 올립니다. 써 보시고 고칠점이나 더 단순
화를 시킬 수 있는 방법을 알려 주시면 정말 감사하겠습니다. 원하는 소유권은 스크립트
실행하면 물어볼 때 입력 해 주면 됩니다. 실행파일의 소유권도 바꾸시길 원하면 file_change
함수만 좀 손보면 됩니다. 이것도 스크립트냐 하고 비난 하시고 싶더라도 제가 첨으로 만
든 거니 그냥 참아 주시면 감사하겠습니다. 이제 걸음마 배우는 놈한테 뛰라고 하진 말아
달라는 부탁입니다. 그럼 어느 한명에게라도 도움이 되길 바라면서... #!/bin/sh # Copyright (c),
2001 Seon-ho Choi, seonho at lycos.com. # This Program is free software; you can redistribute it and/or modify it # under t
he terms of the GNU General Public License as published by the # Free software Foundation; either version 2 of the Licen
se, or (at your # option) any later version.
# This program is distributed in the hopes that it will be useful, but
# without any warranty; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
############################################################################
# Change the mode of all files and directories to set value but not excutable files
# save the dir name found into a variable 'dir$count'
dir_tree() {
count=$(($count+1))
local dir_f="$FILE_NAME"
local temp_dir=dir_f
eval dir$count='$'$temp_dir
}
#change the dir to upper directory when job is done
dir_move_back() {
local D_FLAG=dir$count
local DD_FLAG=''
eval DD_FLAG='$'$D_FLAG
while [ "$DD_FLAG" = "DONE" ];do
local ok="OK"
local o_ok=ok
eval dir$count='$'$o_ok
count=$(($count-1))
if [ "$count" -ge 1 ];then
local dir_b=dir$count
eval dir_bk='$'$dir_b
cd "$dir_bk"
local DD_FLAG
eval DD_FLAG='$'$dir_b
# echo "Now moving back, and working dir is $dir_bk"
else
DIR_0=START_DIR
eval DDIR_0='$'$DIR_0
echo "DDIR_0 is $DDIR_0"
cd "$START_DIR"
echo " Job was done"
fi
if [ "$DDIR_0" = "$START_DIR" ];then
break
fi
done
local D_FL="DONE"
local DD_FL=D_FL
eval dir$count='$'$DD_FL
}
#Change to subdirectory
dir_move_fwd(){
dir_flag=0
dir_forward=dir$count
eval dir_fd='$'$dir_forward
cd "$dir_fd"
echo "I am digging, and current working dir is $dir_fd"
local D_FLAG="DONE"
local DD_FLAG=D_FLAG
eval dir$count='$'$DD_FLAG
}
#Change the mode of files and directories
file_change(){
for FILE_NAME in *
do
if [ -d "$FILE_NAME" ];then
chmod "$DIR_MODE" "$FILE_NAME"
FILE_NAME=$(pwd)/"$FILE_NAME"
dir_tree
dir_flag=1
elif [ -f "$FILE_NAME" ] && [ "$0" = "$FILE_NAME" ];then
echo "$FILE_NAME is $0 itselfe"
echo "$(ls -l "$FILE_NAME")"
elif [ -x "$FILE_NAME" ];then
echo "$(pwd)/$FILE_NAME" IS EXCUTABLE
else
chmod "$FILE_MODE" "$FILE_NAME"
fi
done
}
#Main routine
clear
echo
echo "File and directory mode changing program"
echo "Please, enter the directory to start:"
read START_DIR
echo "Do you want to do for all subdirectories too?, (y/n)"
read ANSWER
echo "Mode for directories ?"
read DIR_MODE
echo "Mode for files ?"
read FILE_MODE
count=0
dir_flag=0
FILE_NAME=""
DIR_0=''
DDIR_0=''
echo "Start DIR is $START_DIR"
cd $START_DIR
case "$ANSWER" in
[Yy] | [Yy][Ee][Ss] )
until [ "$DDIR_0" ]
do
file_change
if [ "$dir_flag" -eq 1 ];then
dir_move_fwd
else
dir_move_back
fi
done
;;
[Nn]* )
file_change
;;
* )
echo "Sorry, answer not recognised"
echo "Please answer yes or no"
exit 1
;;
esac
exit 0--이 곳에 서명을 적어주십시오.
킬리만자로의 표범