• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 541
  • Last Modified:

Bash script to check a process output, then do something

Hi,

Looking for a script to do the following - start the program is its status is not running.
The program returns the string 'not running' if not running, else some other text :

status = /home/user/program getstatus
if (status == 'not running') {
  /home/user/program start
} else {
 // do nothing
}

Can someone help out please.

Thanks
BT
0
brothertom
Asked:
brothertom
1 Solution
 
farzanjCommented:
Try this
status=$(/home/user/program getstatus)
if [[ $status == 'not running' ]]
then
  /home/user/program start
else
 // do nothing
 echo
fi

Open in new window

0
 
TintinCommented:
As a one liner


[ "$(/home/user/program getstatus)" = 'not running' ] && /home/user/program start

Open in new window

0
 
brothertomAuthor Commented:
Many thanks - worked nicely :)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now