2

OpenHardwareMonitor makes log files with date in names in this form:
OpenHardwareMonitorLog-2016-06-16.csv.

On the following day, when computer is started again, the program makes new log file with the name
OpenHardwareMonitorLog-2016-06-17.csv
and so on...

I use the command:

tail -1 OpenHardwareMonitorLog-2016-06-16.csv  | awk -F "," "{print $12}"  

to extract a specific piece of information.

My question is, how can I change this command to simply read from the latest log file, so I don't have to change the log name every day in the above command.

1 Answer 1

3
$ date
Mon Jul 11 16:14:55 IST 2016

$ date +%Y-%m-%d
2016-07-11

$ date --date='-1 day' +%Y-%m-%d
2016-07-10

To view the latest file try,

If file has today's date

tail -1 OpenHardwareMonitorLog-$(date +%Y-%m-%d).csv  | awk -F "," "{print $12}"

If it has yesterday's date

tail -1 OpenHardwareMonitorLog-$(date --date='-1 day' +%Y-%m-%d).csv  | awk -F "," "{print $12}"
0

You must log in to answer this question.

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