There are normally 2 outputs that you see on your screen when you execute a command:
- STDOUT
- STDERR
You can redirect them independently per command.
For example:
ls >out 2>err
will give you two files; out
will contain the output from ls
and err
will be empty.
ls /nonexisting 1>out 2>err
will give you an empty out
file and err
will contain
"ls: cannot access /nonexisting: No such file or directory"
The 2>&1
redirects 2 (STDERR) to 1 (STDOUT)
Your echo
does not have any errors, therefore there is no output on the STDERR.
So your code would probably need to be something like this:
echo "$(date "+%m%d%Y %T") : Starting work"
work_command > work_output 2>> $LOGFILE