I'm trying to take mrt output and put it at the top of a file along with the date and time. I was able to do it at the bottom of the file with the following
printf "********** $(date) **********\n\n" >> $OUTPUT_PATH/$HOSTNAME
mtr -r -w -c 10 $HOSTADDRESS >> $OUTPUT_PATH/$HOSTNAME
printf "\n\n\n\n" >> $OUTPUT_PATH/$HOSTNAME
I found some information on using sed to insert text at the beginning of a file and adapted my code to this
sed -i '1s/^/\n\n\n\n/' $OUTPUT_PATH/$HOSTNAME
sed -i '1s/^/MTR OUTPUT HERE/' $OUTPUT_PATH/$HOSTNAME
sed -i '1s/^/********** $(date) **********\n\n/' $OUTPUT_PATH/$HOSTNAME
This works great except for one issue. The $(date) is being output exactly as is and not showing the current date and time as it did with the printf command.
Any help on this would be appreciated.
Thanks
---------- Post updated 03-03-14 at 12:22 AM ---------- Previous update was 03-02-14 at 11:59 PM ----------
Well I was able to figure it out. All I needed to do was use double quotes for the string.
sed -i "1s/^/********** $(date) **********\n\n/" $OUTPUT_PATH/$HOSTNAME