最近在使用Vagrant,然后发现在MAC下每次启动Vagrant都需要一个个去命令行里面是进入到指定的目录,然后去执行:vagrant up,vagrant reload之类的操作,太麻烦了,那么有没有一些快捷点的操作呢?于是就想到了Shell,使用Shell脚本写一个快速启动的脚本,方便快捷,脚本如下:
1.我是在根目录下创建了一个shell-command目录用于放置shell启动命令
//创建目录
mkdir -m 755 shell-command
//创建文件并写入保存(:wq/:x)
sudo vi shell-command/vagrant.sh
//赋予权限
sudo chmod -R 755 shell-command
./shell-command/vagrant.sh
shell 脚本内容
#!/bin/sh
SERVER=/Users/zhengniu/Downloads/study/vagrant/
read -p "Please Enter box:" dirname
cd $SERVER${dirname:-"docker"}
read -p "Please Enter type(0:start,1:reload,2:halt,3:login):" type
case ${type:-0} in
0)
echo "Begin Run Ubuntu Server"
vagrant up
vagrant ssh
echo "Success"
;;
1)
echo "Begin Reload Vagrant Server"
vagrant reload
vagrant ssh
echo "Success"
;;
2)
echo "Power off Server Server"
vagrant halt
echo "Success"
;;
3)
echo "Login"
vagrant ssh
echo "Success"
;;
*)
echo "exit..."
exit 0
esac
Comment here is closed