Article 5FSM9 A bash script to check the output of a command and run another command.

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.latest?d=yIl2AUoC8zA latest?i=D_jJBf25lNY:0o63Xzwd8XU:F7zBnMy latest?i=D_jJBf25lNY:0o63Xzwd8XU:V_sGLiP latest?d=qj6IDK7rITs latest?i=D_jJBf25lNY:0o63Xzwd8XU:gIN9vFwD_jJBf25lNY
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments