Reading multiple directories and file from them


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reading multiple directories and file from them
# 1  
Old 05-18-2014
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 Smilie

Last edited by Klipeti; 05-18-2014 at 01:06 PM.. Reason: Forgot the mention detail
# 2  
Old 05-18-2014
Try:
Code:
DATE=`date +"%m-%d"`
cd /sys/bus/w1/devices
for sensor in 10-*; do
  cat ${sensor}/w1_slave >> /some/dir/${sensor}_${DATE}.csv
done

# 3  
Old 05-19-2014
Thanks!
That helped Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reading multiple lines in a file

Hello, I am new in shell scripting. I need help regarding following. I have 4 files generated by backups daily. I have stored the names of these 4 files into one file. i.e I have 4 files names as a, b, c & d and these names have been put into one file abcd.txt. Now I want to cat each file in... (7 Replies)
Discussion started by: Ali Sarwar
7 Replies

2. Shell Programming and Scripting

Help with create multiple directories under diff file systems

Hi, Need help ...I want to create multiple directories in different /file systems using for loop..eg.../ORCL_data01/oradata/orcl/ctl. ../ORCL_data01/oradata/orcl/data. ../ORCL_data01/oradata/orcl/redo. Script :- ========= for dir in `ls -d... (8 Replies)
Discussion started by: Linux6.5
8 Replies

3. Shell Programming and Scripting

While loop reading file with multiple conditions

Hi Am trying to print the PIDs of process in a file and trying to grep any PID from that file I set the if condition as $value != "PID" and $value != "-" Assign that number to a variable Am confused since am using while loop to read the line from file and again if condition to check those... (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

4. UNIX for Dummies Questions & Answers

copy file using unix in multiple directories

Hi All Genious, I want to copy a file name XYZ .In a directory /HOME/dir/IXOS1/dir1 which contain multiple directories named not in pattern want to copy the XYZ in all of the directories available on path /HOME/dir/IXOS1/dir1 . Thanks in advance . (2 Replies)
Discussion started by: mumakhij
2 Replies

5. Shell Programming and Scripting

file name shortening for multiple directories

there was a post previously about this from around 2010 but i was unable to get the suggested scripts there to work. the following code works for me when it's saved inside the directory of files whose names i want to shorten, but i would like to be able to store it in a file with a list of ... (4 Replies)
Discussion started by: giseismology
4 Replies

6. UNIX for Dummies Questions & Answers

Deleting multiple directories inside multiple directories

Hi, Very unfamiliar with unix/linux stuff. Our admin is on vacation so, need help very quickly. I have directories (eg 40001, 40002, etc) that each have one subdirectory (01). Each subdir 01 has multiple subdirs (001, 002, 003, etc). They are same in each dir. I need to keep the top and... (7 Replies)
Discussion started by: kkouraus1
7 Replies

7. Shell Programming and Scripting

Multiple jobs reading from same file

I have a sequence of tasks that I routinely run and I'm trying to parallelize certain portions of the sequence. Specifically, there are 3 tasks which all read from the same file, each performing different operations and writing to their own seperate file. I was wondering if I could execute these... (3 Replies)
Discussion started by: erichpowell
3 Replies

8. Shell Programming and Scripting

check if multiple directories exist else create missing directories

Hi , I 'm trying to check if multiple directories exist on a server, if not create the missing ones and print " creating missing directory. how to write this in a simple script, I have made my code complex if ; then taskStatus="Schema extract directory exists, checking if SQL,Count and... (7 Replies)
Discussion started by: ramky79
7 Replies

9. UNIX for Dummies Questions & Answers

Clean directories by reading from file

I have a file in following format directory1=/out/log purgedays1=4 extn1=log,out,txt directory2=/clean/log purgedays2=4 extn2=log,out now i need need to create a script that reads this file and cleans all the files with the given extn from the given directory. The catch here is that... (2 Replies)
Discussion started by: max_payne1234
2 Replies

10. UNIX for Dummies Questions & Answers

Copy single file to multiple directories

Please help - I need to copy a single file to multiple directories. Dir structure: Parent_Directoy Filename1 Child_Directory1 Child_Directory2 Child_Directory3 Child_Directory4 .... So I need to copy Filename1 to all of the... (2 Replies)
Discussion started by: kthatch
2 Replies
Login or Register to Ask a Question