如何读取上一个命令的输出,然后继续执行下一个命令
How to read the output of previous command and then proceed to the next command
我想写一个脚本,只有在上一个命令成功时才会执行下一个命令。
作为脚本的一部分,我正在尝试添加文件。添加文件的命令成功执行后,我会收到如下消息:
May 10, 2019 5:57:12 AM com.ibm.ws.jmx.connector.client.rest.internal.RESTMBeanServerConnection findInitialEndpoint
INFO: CWWKX0230I: The collective member opened JMX client to the collective controller: ncr-aus-e171.corp.wayport.net:9081
May 10, 2019 5:57:12 AM com.ibm.ws.jmx.connector.client.rest.internal.RESTMBeanServerConnection findInitialEndpoint
INFO: CWWKX0230I: The collective member opened JMX client to the collective controller: ncr-aus-e171.corp.wayport.net:9081
Successfully pushed policy to server
收到 "Successfully pushed policy to server" 消息后,我希望脚本推送下一个文件。 (以此类推 50 个不同的文件)
谁能告诉我如何实现它?
试试这个:
#!/bin/bash
Commands=(
"command1 parameter1 parameter2"
"command2 parameter1"
"command3 parameter1 parameter2 parameter3"
)
tmplog=$(mktemp)
for cmd in "${Commands[@]}"; do
echo "$cmd"
$cmd >"$tmplog"
tail -1 "$tmplog" | grep -v "^Successfully" && break
done
rm "$tmplog"
我想写一个脚本,只有在上一个命令成功时才会执行下一个命令。
作为脚本的一部分,我正在尝试添加文件。添加文件的命令成功执行后,我会收到如下消息:
May 10, 2019 5:57:12 AM com.ibm.ws.jmx.connector.client.rest.internal.RESTMBeanServerConnection findInitialEndpoint
INFO: CWWKX0230I: The collective member opened JMX client to the collective controller: ncr-aus-e171.corp.wayport.net:9081
May 10, 2019 5:57:12 AM com.ibm.ws.jmx.connector.client.rest.internal.RESTMBeanServerConnection findInitialEndpoint
INFO: CWWKX0230I: The collective member opened JMX client to the collective controller: ncr-aus-e171.corp.wayport.net:9081
Successfully pushed policy to server
收到 "Successfully pushed policy to server" 消息后,我希望脚本推送下一个文件。 (以此类推 50 个不同的文件)
谁能告诉我如何实现它?
试试这个:
#!/bin/bash
Commands=(
"command1 parameter1 parameter2"
"command2 parameter1"
"command3 parameter1 parameter2 parameter3"
)
tmplog=$(mktemp)
for cmd in "${Commands[@]}"; do
echo "$cmd"
$cmd >"$tmplog"
tail -1 "$tmplog" | grep -v "^Successfully" && break
done
rm "$tmplog"