Reading multiple directories and file from them

Hello

I'm making script for Dallas temperature sensors (DS1820).

When a sensor is connected, it shows up as a directory in /sys/bus/w1/devices
in format 10-xxxxxxx. Inside the directory is a file called w1_slave which holds the temperature in format t=xxxxx.
Each sensor has unique 10-xxxxxxx directory.

I want to make script to go through all 10-xxxxxx folders and read the t=xxxxx from the w1_slave, then save it to file which is named like the directory of the sensor with current date: 10-xxxxxx_date.csv
Also, I use crontab to automatically run the script every 5 minutes, so I need to append new lines to the 10-xxxxxx_date.csv, not replace it!

I know how to read and save the t=xxxxx from w1_slave, but I don't know how to make script automatically go through all 10-xxxxxx folders!
Currently in my script I manually write the sensor's folder and manually write the file where the t=xxxxx is saved.
This is a problem, because what if one of the sensors must be changed or I want to use more or less sensors? I'd have to re-write many lines of the script!

Help is appreciated :slight_smile:

Try:

DATE=`date +"%m-%d"`
cd /sys/bus/w1/devices
for sensor in 10-*; do
  cat ${sensor}/w1_slave >> /some/dir/${sensor}_${DATE}.csv
done

Thanks!
That helped :slight_smile: