bash - Output Shell Script Variable to HTML -
rather new coding, looking little having variable output local html file. both script , html on same machine. script pulls signal level modem , have displayed local html loading screen.
signal script:
#!/bin/bash modem=/dev/ttyusb3 modemcmd=at+csq { echo -ne "$modemcmd"'\r\n' > "$modem" if [ $? -eq 1 ] echo "error"; exit; fi { while read -t 1 if [[ $reply == +csq* ]] arr1=$(echo "$reply" | cut -d' ' -f2) arr2=$(echo "$arr1" | cut -d',' -f1) echo "$arr2" exit; fi done echo "error"; } <"$modem" } 2>/dev/null
would output of display in table on html. thanks!
when host own web server, cgi protocol allows server-side programming in any language like; including bash.
here's simple example serves web page displays current date , time, , refreshes every 10 seconds. put bash script below in file named test.cgi
in cgi-bin
folder (on linux/apache: /usr/lib/cgi-bin
) , make executable (chmod +x test.cgi
). page's url is: http://mywebserver/cgi-bin/test.cgi
#!/bin/bash cat << eot content-type: text/html <!doctype html> <html> <head> <title>test</title> <meta http-equiv="refresh" content="10" /> </head> <body> $(date) </body> </html> eot
please note: empty line below content-type
relevant in cgi protocol.
replace date
own bash script; make sure outputs resembles valid html. means need take effort add html tags markup, , html-encode characters (< > &
) in content.
Comments
Post a Comment