0

We a unix script with gives status of monitoring activity. Eg.

sh monitoring_activity.sh

O/p -

RUNNING| TASK1
RUNNING| TASK2
SUCCESS| TASK3
FAILED | TASK4

Since the number of records are huge ~200, we need to color the output of the script as

  • Record with RUNNING Status in YELLOW
  • Record with SUCCESS Status in GREEN
  • Record with FAILED Status in RED

Is there any way to achieve the same.

Khilesh Chauhan
  • 739
  • 1
  • 10
  • 36
  • https://stackoverflow.com/q/4842424/1030675 – choroba Oct 25 '22 at 10:45
  • (1) One possibility is to adapt the code of your script to emit the escape sequences for colouring. But be careful!!! If you run your script in a terminal which does not support ANSI colour codes (rare nowadays, but not impossible), or redirect the output to another program, where the colouring is a nuisance, your script should emit the lines without colour information. (2) If you don't want to do this, another strategy is to write a wrapper (say: `colorize`), which analyzes the output and inserts the colour codes where necessary. – user1934428 Oct 25 '22 at 11:17
  • Why is this tagged _linux_ **and** _unix_? – user1934428 Oct 25 '22 at 11:18
  • this link has a example to colorize in bash script: [https://stackoverflow.com/questions/57092331/how-to-colorize-command-output-in-bash-script](https://stackoverflow.com/questions/57092331/how-to-colorize-command-output-in-bash-script) – r31sr4r Oct 25 '22 at 11:40

0 Answers0