Currently I have my bash script using exec 22>&2 21>&1 1>$log 2>&1
to write stderr and stdout to a log file. I would like to add a time stamp for each entry, but I haven't found an easy way to do that. Ideally it would be a simple change to the current command with the time being written on the same line before the rest.
Here's a script that I'm using the command in:
#!/bin/bash #This script takes the server to rysnc as an argument. You can also tell #the script to check the server_status.txt file. # #Example: /path/to/script/sync.sh grail true # #The arguments are order senstive. The server name must come before the status #check value. #Logfile LOG=/var/log/sync.log DIRECTORYS="auth/ keys/ log/mailwhen/ intranet/ www/calmaa/data/ www/admatch/data/ www/sfhsa/data/ www/hfa3_org www/padmatch/ www/serverdown/" if [ "x$2" == "xfalse" ]; then return 0 elif [ "x$2" == "xtrue" ]; then if [ `cat /srv/www/wan*/server_status.txt` == "primary" ]; then exit 0 fi else echo "Please use \"true\" or \"false\" for the second value." exit 1 fi # Copy stdout and stderr, and then open the logfile exec 22>&2 21>&1 1>$log 2>&1 # Here is how to restore stdout and stderr: # exec 2>&22 1>&21 for DIRECTORY in $DIRECTORYS; do rsync -azu --delete --bwlimit=500 $1:/srv/$DIRECTORY /srv/$DIRECTORY done