I have a bash script from which i need to write logs. currently i use block like the one below
#log stop request { local now=$(date +"%a %b %d %Y %H:%M:%S") printf "batch stop request successful. \n" printf " Time :: %s\n" "$now" printf " PID of process :: %s\n" ${PID[0]}" } >> "${mylogfile}" where mylogfile variable will have name of the logfile.
The problem with this approach is that when 2 or more instances are running, the logs tends to get messed up with writes from instances coming interleaved.
Please note i used the block thinking that it would result in the log being written to file in one go, thus avoiding the problem.
I have seen logger command from Vivek Gite post. but the problem is it does not write to a file I can specify, rather does so to /var/log/message.
Any help is much appreciated.
Thanks and Regards Sibi
printfstatement? What happens if you forego the multiple lines for a single message and use just one line for the whole message?