I've a small script where it checks for the existence of a particular file and sleeps for 5 seconds if it doesn't exist. I would like to send the sleep output to background so that I don't see so many sleep messages in the build output.
#!/bin/sh -x
until [ -f /tmp/examplefile.txt ]
do
sleep 3
done
echo "File found"
Adding & to the end of the sleep command doesnt work. Any help is much appreciated.
sleep itself does NOT produce any output, as rovf correctly stated. And, as Scrutinizer said, leaving out the -x option will stop xtrace output (which, btw, would go to stderr anyway).
If you are talking of the loop just keeps looping frantically, that's because you put sleep into background, peacefully sleeping there, side by side, while the main loop continues and continues and ...
I want to send these message to background or stop it from printing on screen. From developers point of view, these should not be visible from the output log.
You probably have a set -x inside your script somewhere.
That is what is causes that output, not 'some' error of the code.
Yes, as i've said, "if i may talk about using TUI", those commands are not (yet) part of the default installations.
Wanted to link there, but it seems the thread and its 8 pages is gone from the "Scripts & Programming" sticky section??
---------- Post updated at 19:30 ---------- Previous update was at 19:25 ----------
There is no output log, unless you do log the (specified) output.
That is not applicable here (from what we've seen here).
You could do like:
/path/script.sh 2>/path/to/logfile.everything >&2
# OR
/path/script.sh 2>/path/to/logfile.error >/path/to/logfile.stdout
# OR
/path/script.sh >/path/to/logfile.stdout
Err...
And from within said /path/script.sh, the this would be some sample code:
echo "this is default output" >&1
echo "this is an error message" >&2
echo_fails "This line (its error message) will appear in the error log"
echo "This message will appear in the stdout logfile, if redirected"
@ RudiC, As I said , I run the parent script using sh -xe option for some other purpose and the sleep is just part of the parent script. So i cannot do what Scrutinizer said.