0

I am trying to get bash script output displayed on regular wordpress page.

any ideas ??

code:

#!/bin/bash
mysql -h0.0.0.0 -P3306 -uUSER -pPASSWORD -e "$SQL1" --silent | \
awk 'BEGIN{printf("%-1s%-6s%-6s%-10s%-7s%-13s%-19s%-11s%-10s%-25s%-5s\n",\
"#","lwc","temp","temp [C]","humi","humi[%]","timestamp","lwc_p","lwc_web","lwcGP2Y1010AU0FtimeStamp","lwcGP2Y1010AU0F")}\
{FS=" ";OFS=" | ";OFF="1.05"}\
{print $1=sprintf("%4d",$1),\
$2,\
temp_real=sprintf("%.3f",($2*0.01-40)),\
$3,\
humi_real=sprintf("%.3f",(($2*0.01-40-25)*(0.00008*$3+(0.01))+((-0.0000028*($3^2))+(0.0405*$3)+(-4)))),\
$4" "$5,\
lwc_px=sprintf("%.6f",(($1*(5/1024) - OFF)*(0.5/2.9)*0.7384)),\
lwc_webx=sprintf("%.4f",(0.172*$1-0.0999)*0.7384)}'

expected output:

#lwc   temp  temp [C]  humi   humi[%]      timestamp          lwc_p      lwc_web   lwcGP2Y1010AU0FtimeStamp lwcGP2Y1010AU0F
 186 | 6484 | 24.840 | 1346 | 45.421 | 2016-05-26 16:06:48 | -0.018052 | 23.5491
 186 | 6485 | 24.850 | 1348 | 45.488 | 2016-05-26 16:06:33 | -0.018052 | 23.5491
 186 | 6485 | 24.850 | 1348 | 45.488 | 2016-05-26 16:06:18 | -0.018052 | 23.5491
 186 | 6491 | 24.910 | 1351 | 45.594 | 2016-05-26 16:06:03 | -0.018052 | 23.5491
 186 | 6492 | 24.920 | 1360 | 45.892 | 2016-05-26 16:05:48 | -0.018052 | 23.5491
 186 | 6487 | 24.870 | 1360 | 45.886 | 2016-05-26 16:05:33 | -0.018052 | 23.5491
 186 | 6483 | 24.830 | 1374 | 46.341 | 2016-05-26 16:05:18 | -0.018052 | 23.5491
 186 | 6479 | 24.790 | 1356 | 45.745 | 2016-05-26 16:05:03 | -0.018052 | 23.5491
 186 | 6479 | 24.790 | 1356 | 45.745 | 2016-05-26 16:04:47 | -0.018052 | 23.5491
 186 | 6479 | 24.790 | 1354 | 45.679 | 2016-05-26 16:04:32 | -0.018052 | 23.5491
user2156115
  • 1,169
  • 4
  • 17
  • 30
  • run it though php using `exec()` http://php.net/manual/en/function.exec.php and get the output, just be careful using `exec()` if you have user input in the command string. – ArtisticPhoenix May 26 '16 at 14:17
  • I agree with @ArtisiticPhoenix, perhaps [this](http://stackoverflow.com/questions/17151946/executing-bash-script-from-php-script) could be useful? – fedterzi May 26 '16 at 14:20
  • yes i do know how to exec shell in php, however the question is: where in WORDPRESS page shoule I place that piece of php code ??? – user2156115 May 26 '16 at 14:35
  • The code should go in the functions.php file in the root of your theme, you can create an helper function and either call it from a custom template page, or modify the standard template to check if it's the correct page and call the helper function to get the data. Depending on your situation you need to identify the correct template file, it's usually single.php or page.php depending on whether you are showing the data in a post entry or in a page. – Lud May 26 '16 at 15:59
  • where exacly should I put his little piece of code ??? This little shell script only does echo "hello world"" `$output"; ?>` – user2156115 May 27 '16 at 12:50

0 Answers0