while sleep 4; cat temperature

D

Dan Jacobson

How might I do this more efficiently?
while sleep 4; do perl -anwe 'print $F[1]." "' \
/proc/acpi/thermal_zone/THM0/temperature; done
First, no need for more than one process.
Second, must reopen the file each time.
Third, maybe there's a proc:: module that can help?
 
X

xhoster

Dan Jacobson said:
How might I do this more efficiently?
while sleep 4; do perl -anwe 'print $F[1]." "' \
/proc/acpi/thermal_zone/THM0/temperature; done
First, no need for more than one process.

OK. Then don't use more than one. Put the while inside the Perl, rather
than inside the bash.
Second, must reopen the file each time.

OK, so do that. perldoc -f open.
Third, maybe there's a proc:: module that can help?

Why would Proc module help if there is no need for more than one process?

If you demonstrated at least some attempt to do this in Perl before asking,
you might get better responses.

Xho
 
X

Xicheng

Dan said:
How might I do this more efficiently?
while sleep 4; do perl -anwe 'print $F[1]." "' \
/proc/acpi/thermal_zone/THM0/temperature; done
First, no need for more than one process.
Second, must reopen the file each time.
Third, maybe there's a proc:: module that can help?

I guess you dont need to reopen file each time, you can reset the
filehandle to the beginning of your file every 4 seconds, then go
through the file again...

perl -e 'open
$fh,"</proc/acpi/thermal_zone/THM0/temperature";while(1){print+(split)[1]."
"while<$fh>;sleep(4);seek($fh,0,0)}'

Code untested on any imcresing files.
Xicheng
 
X

Xicheng

Xicheng said:
perl -e 'open
$fh,"</proc/acpi/thermal_zone/THM0/temperature";while(1){print+(split)[1]."
"while<$fh>;sleep(4);seek($fh,0,0)}'
perl -e 'open
$fh,"</proc/acpi/thermal_zone/THM0/temperature";while(1){print+(split)[1]."
"while<$fh>;print"\n";sleep(4);seek($fh,0,0)}'

Better add a newline at the end of each break....it seems a buffer
problem if no newline shows up in the output texts even though they are
printed to STDOUT...

Xicheng
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,177
Messages
2,570,953
Members
47,507
Latest member
codeguru31

Latest Threads

Top