Bash – Merge two command results to one line when redirecting stdout

bashstdout

In a cron script I want to log CPU temperatures in the format

[datetime] temp

using date and acpi -t. How can I redirect (>>) these two commands to a single line in the log file?

Best Answer

Try simply doing:

echo $(date) $(acpi -t) >> your_log_file

You might want to specify a compact date format to make your log file more easy to parse and to be independent of environment/locale settings (something like $(date +"%Y%m%d %H%M%S") for example).