Self-Improvement
12) 쉘 프로그래밍 실습 2 본문
*원격 서버의 자동 명령어 수행
#vi telnet.sh
#chmod 755 telnet.sh
#telnet.sh
*특정 경로의 파일 확장자 변경
#vi move.filename.sh
#chmod 755 move.filename.sh
#move.filename.sh /root/bin txt els
*환경 설정 스크립트
#vi ENV_main.sh
--------ENV_main.sh----------
/root/bin/ENV1.sh
/root/bin/ENV2.sh
/root/bin/ENV3.sh
----------------------------
#chmod 755 ENV_main.sh
#vi ENV1.sh (telnet, ssh Open서비스 진행)
------------ENV1.sh------------
#!/bin/bash
# (1) Telnet Service Open
echo "--------ENV1.sh---------"
service xinetd restart > /dev/null 2>&1
chkconfig krb5-telnet on
if [ $? -eq 0 ] ; then
echo "[ ok ] : Phase 1(telnet)"
else
echo "[ FAIL ] : Phase 1(telnet)"
exit 1
fi
#for i in `seq 1 11`
#do
# grep pts/$i /etc/securetty
# if [ $? -eq 1 ] ; then
# echo "pts/$i" >> /etc/securetty
# echo "pts/$i is in /etc/securetty"
# fi
#done
if ! grep pts /etc/securetty > /dev/null 2>&1 ; then
for i in `seq 1 11`
do
echo "pts/$i" >> /etc/securetty
done
else
echo "InputError : /etc/securetty already 'pts'"
fi
# (2) vsftpd service open
chkconfig vsftpd on
service vsftpd restart > /dev/null 2>&1
if [ $? -eq 0 ] ; then
echo "[ ok ] : Phase 2(ftp)"
else
echo "[ FAIL ] : Phase 2(ftp)"
exit 1
fi
sed -i '/^root/d' /etc/vsftpd/ftpusers
sed -i '/^root/d' /etc/vsftpd/user_list
---------------------------------
#chmod 755 ENV1.sh
#vi ENV2.sh (bashrc에 입력)
----------ENV2.sh-------------
#!/bin/bash
BASHRC1=/root/bin/bashrc
cat << EOF > $BASHRC1
# .bashrc
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
alias c='clear'
alias ls='/bin/ls --color=tty -h'
alias grep='/bin/grep --color -i'
alias vi='/usr/bin/vim'
alias df='df -T -h'
alias dff='df -T -h ; echo ; df -i'
alias pss='ps -ef | head -1 ; ps -ef | grep $1'
alias pp='chmod 755 /root/bin/*.sh'
export PS1='\[\033[32m\][\h@\w]\[\033[00m\]\$ '
export HISTTIMEFORMAT='%C %T '
set -o vi
EOF
echo "--------ENV2.sh---------"
if [ $? -eq 0 ] ; then
echo "[ ok ] : Phase 3(bashrc)"
else
echo "[ FAIL ] : Phase 3(bashrc)"
fi
-----------------------------
#chmod 755 ENV2.sh
#vi ENV3.sh (gcc패키지 설치)
--------ENV3.sh---------------
#!/bin/bash
echo "--------ENV3.sh---------"
for PKG in gcc
do
yum -y install $PKG | grep 'No package'
if [ $? -eq 0 ] ; then
echo "[ FAIL ] : Phase 4($PKG)"
else
echo "[ Ok ] : Phase 4($PKG)"
fi
done
------------------------------
#chmod 755 ENV3.sh
#ENV_main.sh
'프로그래밍 > Shell' 카테고리의 다른 글
14) 쉘 프로그래밍 실습4 (0) | 2018.10.21 |
---|---|
13) 쉘 프로그래밍 실습3 (echo escape character) (0) | 2018.10.21 |
11) 쉘 프로그래밍 실습1 (0) | 2018.10.21 |
10) 쉘 스크립트 : 루프제어 (0) | 2018.10.21 |
9) 쉘 스크립트 반복문 : while (0) | 2018.10.21 |