I am still a bottle feeding linux newbie, so go easy. I've googled myself this far but can't find the answer.
I'm running a program that outputs csv data, and piping it to log.csv
I'm looking for a way to have the piped output contain the date/time it was created.
Right now the command looks like this (hand key'd every morning, no crontab yet until I get this working)
rtlamr -format=csv -msgtype=scm | tee /home/jonboy545/energy/logs/3-16-18_7_30.csv
| tee so I can still see the output on the terminal as well as log the file.
So, how do I pipe the output to a dynamic filename? I have a simple bash script that will output text but how do I tell rtlamr to | a bash script to generate a filename?
Here's the script called "log_energy.sh" to create the text file name:
#!/bin/bash today=`date '+%m_%d__%H_%M_%S'`; filename="/home/jonboy545/energy/logs/$today.csv" echo $filename;
If you run
./log_energy.shthen it just outputs the text like you'd expect:
So my stupid thinking is something like this (which obviously doesn't work)
rtlamr -format=csv -msgtype=scm | tee /home/jonboy545/./log_energy.sh
Now that I think about it, it may be easier to just create a script that does all that. So something like this?
#!/bin/bash today=`date '+%m_%d__%H_%M_%S'`; filename="/home/jonboy545/energy/logs/$today.txt" /usr/bin/rtlamr -format=csv -msgtype=scm | tee $filename;
Thinking I may have just answered my own post but I'm sure that script above has got something wrong with it.