使用多个命令运行iocage exec

时间:2019-10-05 01:49:12

标签: bash

而不是像下面这样多次调用iocage exec:

iocage exec "${JAIL_NAME}" chown 0:0 /settings/ipfw_rules
iocage exec "${JAIL_NAME}" chmod 600 /settings/ipfw_rules
iocage exec "${JAIL_NAME}" sysrc "firewall_enable=YES"
iocage exec "${JAIL_NAME}" sysrc "firewall_type=/settings/ipfw_rules"
iocage exec "${JAIL_NAME}" sysrc "openvpn_enable=YES"
iocage exec "${JAIL_NAME}" sysrc "openvpn_dir=/settings"
...

我可以使用这样的东西吗?

cat <<-EOF | iocage exec "${JAIL_NAME}"
    chown 0:0 /settings/ipfw_rules
    chmod 600 /settings/ipfw_rules
    sysrc "firewall_enable=YES"
    sysrc "firewall_type=/settings/ipfw_rules"
    sysrc "openvpn_enable=YES"
...
EOF

1 个答案:

答案 0 :(得分:1)

您可以使用'xargs'从标准输入构造命令:

cat <<-EOF | xargs -L1 iocage exec "${JAIL_NAME}"
  Command Here
...
EOF