0

I have rather complex bash script which is normally run manually and thus needs live output on the console (stdout and stderr). However, since the outcome and output of this script is rather important I'd like to save its output at the end into a database.

I have already a trap function for this and the database query as such is also not a problem. The problem is: How do I get the output of the entire script till that point into a variable?

The live console output should be preserved. The output after the database query (if any) does not matter.

Is this possible at all? Might it be necessary to wrap the script into another script (file)?

2
  • Use tee to add output to a file and read from file Commented Sep 8, 2020 at 7:00
  • 1
    Show the script you have, with a minimal reproducible example and an exact output you need Commented Sep 8, 2020 at 7:00

1 Answer 1

1

I'm doing similar task like this

exec 5>&1
message=$(check|tee /dev/fd/5)
mutt -s "$subjct" "$mailto" <<< "$message"

Add your script instead of check function and change mailing to db query.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for that answer. I think that goes in the right direction. I have put a follow up question here: stackoverflow.com/questions/63792514/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.