每天下班要把5台虚拟机suspend,上班在start,点鼠标很不爽,因此考虑用vmrun写个脚本来跑。
Contents
环境要求
- Windows机器要安装msys2或者msys
- 配置vmrun path
vmrun power 相关参数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
$ vmrun.exe --help Invalid argument: --help vmrun version 1.14.2 build-2780323 Usage: vmrun [AUTHENTICATION-FLAGS] COMMAND [PARAMETERS] ... POWER COMMANDS PARAMETERS DESCRIPTION -------------- ---------- ----------- start Path to vmx file Start a VM or Team [gui|nogui] stop Path to vmx file Stop a VM or Team [hard|soft] reset Path to vmx file Reset a VM or Team [hard|soft] suspend Path to vmx file Suspend a VM or Team [hard|soft] pause Path to vmx file Pause a VM unpause Path to vmx file Unpause a VM |
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
#!/bin/bash dir="/e/VMs/" [ $# -lt 1 ] && echo "args error" && exit 1 func=$1 echo $func; function prompt() { read -p "are you sure?(y/n)" p case $p in y) return 0;; n) exit 1;; *) echo "accept y,n" && exit 1;; esac } case $func in start) prompt;; stop) prompt;; pause) prompt;; unpause) prompt;; suspend) prompt;; *) echo "accept start, stop, pause, unpause, suspend" && exit 1;; esac for id in `find ./ $dir -name "*.vmx"`;do vmrun $func $id echo "$id $func..." done |
vagrant 适合这种场景
厉害~