Siqko
Siqko

Reputation: 39

How do you temporarily hide the output of a bash script that is running?

This question may or may not have been asked already, I couldn't find it anywhere & I'm a bit of a Linux beginner.

I got a ./start.sh script that runs on my RHEL 4 server and sends out trace outputs every other second. Example: Trace: Server Running on alias 1, 2 etc... it's there to make sure the server didn't drop out.

I need to run some of my DDoS protection tools and scanners as this is running all at the same time. Though I can't ever see what's going on because of all the trace output!

How would I go about temporarily disabling output as it is ALREADY running, while keeping it running in the background then running my tools and then when I'm done re-enabling the output again?

Upvotes: 2

Views: 1226

Answers (1)

Emmet
Emmet

Reputation: 6401

I can see two solutions:

  • use screen (preferably), or
  • use redirection and tail.

For example:

$ stdbuf -oL ./start.sh > /tmp/start.sh.log &
$ tail -f /tmp/start.sh.log

After doing this, you can see the log messages in your terminal. You can kill tail with impunity and start it again whenever you want to see the messages. When the log file gets too big, you can shorten it to zero with:

$ echo -n > /tmp/start.sh.log

Bash's redirect can seamlessly handle the file suddenly getting truncated. Not sure if this is true for all shells. You can interpose tee if that becomes a problem with your shell.

I added the stdbuf -oL to “encourage” the shell-script to line-buffer stdout. Any commands in there that buffer their own output won't be affected, but it might help.

Upvotes: 1

Related Questions