0

I'm completely new to SSH and I'm trying different things. I wanted to write my custom commands output to a log file.
Here is my command:

hostname:~$ sudo checktemp grep
/dev/sda: ST3320820AS: 38°C
coretemp-isa-0000
Adapter: ISA adapter
Core 0:       +45.0°C  (high = +78.0°C, crit = +100.0°C)
Core 1:       +45.0°C  (high = +78.0°C, crit = +100.0°C)
radeon-pci-0100
Adapter: PCI adapter
temp1:        +59.0°C

I want to write to file the following:

ST3320820AS: 38°C
Core 0:       +45.0°C
Core 1:       +45.0°C
temp1:        +59.0°C

I looked up grep command but no success. Additionaly I would like to now how to set the log file destination and wrote settings (write new line etc.).

I would like the log file to look like below:

ST3320820AS; Core 0; Core 1; temp1; date; time

38°C; +45.0°C; +45.0°C; +59.0°C; yyyy-mm-dd; hh:mm:ss

Thanks for your help.

2
  • Nope, I did not. Can we have them back? Commented Jul 1, 2015 at 16:49
  • How is ssh relevant here? Commented Jul 1, 2015 at 16:52

1 Answer 1

1

To create the log file:

sudo checktemp | grep -E "Core|temp1|sda" | awk -F"(" '{print $1}' | sed 's,/dev/sda: ,,g' > log

To append to the end of the log file:

sudo checktemp | grep -E "Core|temp1|sda" | awk -F"(" '{print $1}' | sed 's,/dev/sda: ,,g' >> log

To print in the one-line format with the date and the time:

sudo checktemp | grep -E "Core|temp1|sda" | awk -F"(" '{print $1}' | sed 's,/dev/sda: ,,g' | sed 's, ,,g' > log

echo -n date: >> log
date +%Y-%m-%d >> log
echo -n time: >> log
date +%H=%M=%S >> log

cat log | awk -F":" '{ for (i=1; i<=NF; i++) { a[NR,i] = $i } } ; NF>p { p = NF } END { for(j=1; j<=p; j++) { str=a[1,j] ; for(i=2; i<=NR; i++){ str=str"; "a[i,j]; } print str } }' | sed 's,Core,Core ,g;s,=,:,g' > log.txt

Sign up to request clarification or add additional context in comments.

2 Comments

where is this log file created? can this log file be in txt format?
OK, I found the log file but. As in the original question, I would like the values to be in one line separated with semicolon. How do I achieve that?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.