linux - convert a simple temperature bash script to javascript -


i have bash script spit out cpu temperature in beaglebon black. need convert these javascript. @ linux command , javascript have idea how ?

i thinking of using fs.readfile command not sure.

here code in bash script , link of got from:

bash script link

# cpu temp monitor  # ctrl-c stop  # written brian heckathorne - me@godfear.org   # modified richard st-pierre - inspire.logicsupply.com  # simple script monitoring cpu temp on beaglebone black running debian      #!/bin/bash  (( ; ; ))           echo -n "cpu temp [celsius]: "          cat /sys/class/hwmon/hwmon0/device/temp1_input | sed 's/...$//'          sleep 2  done

here more-or-less literal port.

a few caveats:

  • i infer file has 1 line in it. if that's not correct, code may need tweak.

  • this more-or-less literal port, meaning make no judgments whether cat (and, therefore, fs.readfilesync()), regexp replacement, etc., best choices here. i'm mapping bash code node.js code, more or less.

with out of way, here go:

#!/usr/bin/env node  var fs = require('fs');  var temperaturefile = '/sys/class/hwmon/hwmon0/device/temp1_input';  var displaytemperature = function () {     process.stdout.write("cpu temp [celsius]: ");     process.stdout.write(fs.readfilesync(temperaturefile, {encoding: 'utf-8'})         .replace(/...$/g, '\n')); }  displaytemperature(); setinterval(displaytemperature, 2000); 

Comments

Popular posts from this blog

javascript - Complete OpenIDConnect auth when requesting via Ajax -

php - Wordpress: Link a post to posts of another category manually -

apache - PHP Soap issue while content length is larger -