I have a script like this:
#!/usr/bin/bash
COMMAND='some_command >> some_log_file 2>&1'
until $COMMAND; do
echo "some_command crashed with exit code $?. Respawning.." >&2
sleep 1
done
(I got the until ... done
bit from https://stackoverflow.com/a/697064/88821 , FWIW, but changed it a bit.)
While some_command
is being run, the problem is that the output is not going to some_log_file
. Instead, it goes to the stdout of the shell from which I ran this wrapper script. How can I get the output to go to some_log_file
while keeping the entire command (including redirects) in the variable COMMAND
? The idea is to use this script as a more general wrapper script that can be used with other programs. (COMMAND
is actually being passed as an argument into the script).