0

I have some existing shell scripts, some of which have echo statements rather than logging statements. In a 3 node cluster, if a non master node is down, the master node's script is triggered. When I reboot the non master node, I need to view the echo statements in the master node's script to see what's happening. The script is auto executed by a trigger which detects when a server is down. How do I view the echo statements?

dozer
  • 861
  • 1
  • 11
  • 22
  • It depends how the script is run. Script output isn't automatically logged in general, but the "trigger" that's executing the script might save its output somewhere. – John Kugelman Mar 14 '19 at 15:35
  • I don't think that's happening in this case. Will all echo statements be lost outside of the shell in which it's run? – dozer Mar 14 '19 at 15:36
  • Yes, they will. – John Kugelman Mar 14 '19 at 15:50
  • 1
    `echo` itself does nothing but send bytes to standard output, whatever file that may be. The answer to this depends *entirely* on how standard output is set for the process in question. – chepner Mar 14 '19 at 16:41
  • What do you mean by setting a standard output @chepner – dozer Mar 14 '19 at 17:36
  • @dozer Whatever runs ("trigger"s) the script will, either explicitly or implicitly, provide the script with file handles for it to send standard and error output to. These could be a terminal (e.g. when you run things interactively), they could be disk file(s), pipe(s) to another program, /dev/null, whatever. One option is to set/replace those file handles so output goes somewhere like a file that you can then read. Or you could edit the script so it does proper logging. – Gordon Davisson Mar 14 '19 at 18:00
  • `command` prints to the console where the command was started; `command >file 2>&1` Instead saves that output to a file you can inspect later. This is very basic Unix fundamentals. – tripleee Mar 14 '19 at 18:24
  • Thanks guys. This helped. I managed to redirect the output to a file using your inputs and this link - https://stackoverflow.com/questions/637827/redirect-stderr-and-stdout-in-bash – dozer Mar 14 '19 at 19:51

0 Answers0