一个简单的shell脚本-----实现虚拟机实验环境的简单配置

网友投稿 497 2023-03-17

本站部分文章、图片属于网络上可搜索到的公开信息,均用于学习和交流用途,不能代表睿象云的观点、立场或意见。我们接受网民的监督,如发现任何违法内容或侵犯了您的权益,请第一时间联系小编邮箱jiasou666@gmail.com 处理。

一个简单的shell脚本-----实现虚拟机实验环境的简单配置

亲自写过shell脚本后才发现,这玩意真是太方便了,当你想把一些琐碎的、细节性的小指令一次性来完成时,脚本无疑是最好的选择,方便、快捷,关键是真是懒人必备啊。

由于安装的centos6.5是最小化安装,且是实验环境,即安装在vmware workstations上面,在首次安装完成后,配置完IP地址的相关信息后,就做了一个初始的快照,以便下次实验完后,可以通过快照快速还原系统。

但是由于实验环境的要求,例如防火墙、SELinux、光盘挂载、yum源配置等,都是最常需要修改的选项,并且由于最小化安装,系统里并没有vim编译工具和man手册的查询,所以导致每次还原快照后,还要处理这些琐碎的问题。为此,我就专门写了这么一个小脚本,内容并不复杂,但是也是一种学习过程,发出来和大家一起分享一下,顺便求指教......

代码:#!/bin/bash# Config some simple order when the system start# Create by phoenix # Specify the pathserver=/etc/init.dyum=/etc/yum.repos.dmountdir=/media/cdromselinux=/etc/selinux/config # stop the iptabes and set it can't start when the system start$server/iptables stop &>/dev/nullif [ "$?" = "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 systemsetenforce 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-ROMmount |grep sr0 &>/dev/nullif [ ! "$?" = "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 yumif [ -e $yum/CentOS-Base.repo ];then   mv -f $yum/CentOS-Base.repo $yum/CentOS-Base.repo.bak &>/dev/nullelse   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 languageecho "#LANG=zh_CN.UTF-8" >/etc/sysconfig/i18necho "6# The language is modify successfully" # Install the tools "VIM" and "MAN"echo "7# Starting install vim and man,please wait......"sleep 3yum install vim man -y &>/dev/null # Reboot the system when all the work is doneecho "#########  All work is done  ########"sleep 2echo "Please wait the syatem restart......"sleep 2init 6

代码:#!/bin/bash# Config some simple order when the system start# Create by phoenix # Specify the pathserver=/etc/init.dyum=/etc/yum.repos.dmountdir=/media/cdromselinux=/etc/selinux/config # stop the iptabes and set it can't start when the system start$server/iptables stop &>/dev/nullif [ "$?" = "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 systemsetenforce 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-ROMmount |grep sr0 &>/dev/nullif [ ! "$?" = "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 yumif [ -e $yum/CentOS-Base.repo ];then mv -f $yum/CentOS-Base.repo $yum/CentOS-Base.repo.bak &>/dev/nullelse 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 languageecho "#LANG=zh_CN.UTF-8" >/etc/sysconfig/i18necho "6# The language is modify successfully" # Install the tools "VIM" and "MAN"echo "7# Starting install vim and man,please wait......"sleep 3yum install vim man -y &>/dev/null # Reboot the system when all the work is doneecho "######### All work is done ########"sleep 2echo "Please wait the syatem restart......"sleep 2init 6

上一篇:在Ubuntu上安装类Winamp的音频播放器Qmmp 0.9.0
下一篇:如何应对“臭名昭著”的云计算安全问题?
相关文章

 发表评论

暂时没有评论,来抢沙发吧~