一個簡單的shell腳本-----實現虛擬機實驗環境的簡單配置

    親自寫過shell腳本後才發現,這玩意真是太方便了,當你想把一些瑣碎的、細節性的小指令一次性來完成時,腳本無疑是最好的選擇,方便、快捷,關鍵是真是懶人必備啊。
linux

    因爲安裝的centos6.5是最小化安裝,且是實驗環境,即安裝在vmware workstations上面,在首次安裝完成後,配置完IP地址的相關信息後,就作了一個初始的快照,以便下次實驗完後,能夠經過快照快速還原系統。
shell

    可是因爲實驗環境的要求,例如防火牆、SELinux、光盤掛載、yum源配置等,都是最常須要修改的選項,而且因爲最小化安裝,系統裏並無vim編譯工具和man手冊的查詢,因此致使每次還原快照後,還要處理這些瑣碎的問題。爲此,我就專門寫了這麼一個小腳本,內容並不複雜,可是也是一種學習過程,發出來和你們一塊兒分享一下,順便求指教......
vim

#!/bin/bash
# Config some simple order when the system start
# Create by phoenix

# Specify the path
server=/etc/init.d
yum=/etc/yum.repos.d
mountdir=/media/cdrom
selinux=/etc/selinux/config

# stop the iptabes and set it can't start when the system start
$server/iptables stop &>/dev/null
if [ "$?" = "0" ]; then
   chkconfig iptables off
   chkconfig ip6tables off
   echo "1# The iptables stop successfully"
else
   echo "1# The iptables stop failed"
fi

# shutdown the selinxu system
setenforce 0 && sed -e 's/^SELINUX=enforcing/SELINUX=disabled/g' $selinux >$selinux.bak 
mv -f $selinux.bak $selinux 
echo "2# The selinux system is disabled"

# Mount the CD-ROM
mount |grep sr0 &>/dev/null
if [ ! "$?" = "0" ]; then
   if [ ! -e $mountdir ]; then
      mkdir -p $mountdir &>/dev/null
   else
      mount /dev/cdrom $mountdir &>/dev/null
      echo "3# The CD-ROM is mounting successfully"
   fi   
else
   echo "3# The CD-ROM is already mounted" 
fi

# Config the source of yum
if [ -e $yum/CentOS-Base.repo ];then
   mv -f $yum/CentOS-Base.repo $yum/CentOS-Base.repo.bak &>/dev/null
else
   echo "4# Starting config the source of yum"
	sleep 3 
fi

 sed  -e 's/^enabled=0/enabled=1/g' $yum/CentOS-Media.repo >$yum/CentOS-Media.repo.bak 
 mv -f $yum/CentOS-Media.repo.bak $yum/CentOS-Media.repo>>/dev/null

yum clean all &>/dev/null &&echo "5# The source of yum configed successfully"

# Modify the code of language
echo "#LANG=zh_CN.UTF-8" >/etc/sysconfig/i18n
echo "6# The language is modify successfully"

# Install the tools "VIM" and "MAN"
echo "7# Starting install vim and man,please wait......"
sleep 3
yum install vim man -y &>/dev/null

# Reboot the system when all the work is done
echo "#########  All work is done  ########"
sleep 2
echo "Please wait the syatem restart......"
sleep 2
init 6


    另外,請不要吐槽個人英語。。。。雖然過了四級而且差點過了六級,然而仍是沒有什麼用。。。
centos

相關文章
相關標籤/搜索