虚拟机脚本
2016-07-21 17:35
387 查看
#!/bin/bash #author my #mk virtual add() { if [[ "$1" =~ [[:digit:]]+ ]] then local w=`ls /httpdtest/html/ | grep -o "[[:digit:]]\+" | sort -n | tail -1 |grep -o "[[:digit:]]*"` local y=$[$w+1] local z=$[$y-1+$1] for i in `seq $y $z` do touch /etc/httpd/conf.d/virtualhost${i}.conf mkdir -pv /httpdtest/html/www$i > /dev/null touch /httpdtest/html/www${1}/index.html echo -e "<h>test$i</h>" > /httpdtest/html/www${i}/index.html echo -e "<VirtualHost 172.16.7.3:80>\nServerName www${i}.mymy.com\nDocumentRoot /httpdtest/html/www${i}\n</VirtualHost>" > /etc/httpd/conf.d/virtualhost${i}.conf echo "172.16.7.3 www${i}.mymy.com" >> /etc/hosts service httpd reload >/dev/null done else echo "sorry ,add + number" fi } del() { #local w=`ls /httpdtest/html/ | sort -n | tail -1 |grep -o "[[:digit:]]*"` #local y=$[$w+1] #local z=$[$w+1-$1] if [[ "$1" =~ [[:digit:]]+ ]] then #for i in `seq $z $w` # do #rm -rf /httpdtest/html/www$i >/dev/null rm -rf /etc/httpd/conf.d/virtualhost${1}.conf >/dev/null #done else case $1 in "-a") read -p "sure ? (y/n)" m if [ "$m" == "y" ] then rm -rf /etc/httpd/conf.d/virtualhost* >/dev/null else exit fi ;; *) echo "input number or -a " ;; esac fi } list() { if [ "$1" == "-a" ] then httpd -S |sed -n '/^V/,/^w/p' | sed '/^w/d' else if [[ "$1" =~ [[:digit:]]+ ]] then file=/etc/httpd/conf.d/virtualhost`echo $1`.conf if [ -e "$file" ] then cat $file else echo " no exist" read -p "do you want to create (y/n):" p case $p in y) touch /etc/httpd/conf.d/virtualhost${1}.conf mkdir -pv /httpdtest/html/www$1 > /dev/null touch /httpdtest/html/www${1}/index.html echo -e "<h>test$1</h>" > /httpdtest/html/www${1}/index.html echo -e "<VirtualHost 172.16.7.3:80>\nServerName www${1}.mymy.com\nDocumentRoot /httpdtest/html/www${1}\n</VirtualHost>" > /etc/httpd/conf.d/virtualhost${1}.conf echo "172.16.7.3 www${1}.mymy.com" >> /etc/hosts service httpd reload >/dev/null ;; *) exit ;; esac fi else echo "sorry,just number" fi fi } case $1 in list*) list $2 ;; add*) add $2 ;; del*) del $2 ;; *) echo "error input" ;; esac #if [[ "$k" =~ \+[[:digit:]]+ ]] # then # w=`ls /httpdtest/html/ | sort -n | tail -1 |grep -o "[[:digit:]]*"` # y=$[$w+1] # z=$[$y+$k-1] # for i in `seq $y $z` # do # p=`echo $k | grep -o "[[:digit:]]\+"` # mkvirtual $p # done #elif [[ "$k" =~ \-[[:digit:]]+ ]] # then # r=`echo $k | grep -o "[[:digit:]]\+" # delvirtual $r #else # echo "an yao qiu shu ru" #fi
相关文章推荐
- Linux socket 初步
- Linux Kernel 4.0 RC5 发布!
- linux lsof详解
- linux 文件权限
- Linux 执行数学运算
- 10 篇对初学者和专家都有用的 Linux 命令教程
- Linux 与 Windows 对UNICODE 的处理方式
- Ubuntu12.04下QQ完美走起啊!走起啊!有木有啊!
- 解決Linux下Android开发真机调试设备不被识别问题
- 运维入门
- 运维提升
- Linux 自检和 SystemTap
- Ubuntu Linux使用体验
- c语言实现hashmap(转载)
- Linux 信号signal处理机制
- linux下mysql添加用户
- Scientific Linux 5.5 图形安装教程
- Linux 下无损图片压缩小工具介绍