我正在尝试编写一个鱼脚本来检查当前的流浪者状态并根据它做一些事情。一个简单的例子是:
检查流浪汉是否在运行,如果是,流浪汉停止,如果没有…
找到了带有test和$ status的解决方案
# Get statusvagrant status —machine-readable | grep state,runningCheck statusif test $status -eq 0# Vagrant is runningvagrant halt# Send notificationnotify-send "Vagrant is halted."else# Vagrant is not runningvagrant up# Send notificationnotify-send "Vagrant is up."end</code>
# Get status
vagrant status —machine-readable | grep state,running
Check statusif test $status -eq 0
if test $status -eq 0
# Vagrant is running
vagrant halt
# Send notification
notify-send "Vagrant is halted."
else
# Vagrant is not running
vagrant up
notify-send "Vagrant is up."
end
</code>