I have an issue with a shell script that uses rsync to synchronize 2 directories. I'm storing the result of the rsync command (whether it's successful or not) to a file named status and in case there is a problem, the stderr output is appended to a file named error. However, I can't seem to find a way to enter a timestamp before the actual error in the error file.
In the end, I need something like this:
if rsync source destination 2>> error # but I need to have the date before the actual error is appended! then echo "`date` - Success" >> status else echo "`date` - Failure" >> status fi
I've also tried the following:
(rsync source destination && echo "`date` - Success" >> status || echo "`date` - Failure" >> status) 2>>error
The only way I've made this work is when I store the stderr output to a temporary file, so that I can append its contents to the error file after I have entered the timestamp.