A bash script to check the output of a command and run another command.
by n00b_noob from LinuxQuestions.org on (#5FSM9)
Hello,
I want to write a bash script that checks the output of a command and if a specific string existed in the output of that command, then run another command. For example, if in the below output, "Offline: node1" existed then run a specific command:
Code:# pcs status nodes
Pacemaker Nodes:
Online: node1
Standby:
Standby with resource(s) running:
Maintenance:
Offline: node2I found a script about check the status of a website:
Code:#!/bin/bash
ping -c 3 www.URL.com > /dev/null
if [ $? != 0 ]
then
echo "Site is down."
fiHow can I execute a command in a script, then check its output for a specific string?
Thank you.


I want to write a bash script that checks the output of a command and if a specific string existed in the output of that command, then run another command. For example, if in the below output, "Offline: node1" existed then run a specific command:
Code:# pcs status nodes
Pacemaker Nodes:
Online: node1
Standby:
Standby with resource(s) running:
Maintenance:
Offline: node2I found a script about check the status of a website:
Code:#!/bin/bash
ping -c 3 www.URL.com > /dev/null
if [ $? != 0 ]
then
echo "Site is down."
fiHow can I execute a command in a script, then check its output for a specific string?
Thank you.