Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 7 down vote accepted

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).

share|improve this answer

well perhaps on older systems (solaris8 f.e. ^^) without bash:

x=`date '+%Y%m%d %H%M%S'`; y=`acpi -t`; echo "$x $y" >>your_log_file
share|improve this answer
Even Solaris 8 understands $(…), it's POSIX-compliant. But you have to use /usr/xpg4/bin/sh instead of /bin/sh, Solaris 8's /bin/sh is still a Bourne shell. – Gilles Sep 3 '12 at 23:06
Aaah, never used /usr/xpg4/bin/sh, we would have saved some efforts those days using just the Bourne shell. – wolf Sep 4 '12 at 10:25
Like this one... – mikiemorales Jul 18 '14 at 20:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.