Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

2 Answers 2

up vote 5 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
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. –  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 at 20:38

Your Answer

 
discard

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.