8

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?

0

2 Answers 2

12

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

4

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
3
  • 1
    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. Commented Sep 3, 2012 at 23:06
  • Aaah, never used /usr/xpg4/bin/sh, we would have saved some efforts those days using just the Bourne shell.
    – numchrun
    Commented Sep 4, 2012 at 10:25
  • Like this one... Commented Jul 18, 2014 at 20:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .