RE: OT: How to embed or call a shell script in an html file?

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Paul Mooring
Date:  
To: Main PLUG discussion list
Subject: RE: OT: How to embed or call a shell script in an html file?
So allow me to play devil's advocate here. SSI (server side includes) is not really what Joe was asking about, his question was closer to using bash cgi. While actually writing something in bash might be a royal pita, I would argue it's not inherently problematic especially if you already have some working code. I think the problem stems from the face that not enough people really understand modern web servers. Web servers only display static assets to clients (generally browsers), that means if you're using a LAMP set up a PHP vm running in mod-php actually runs the PHP code and then apache serves up the static content to the client.

A more common architecture has become nginx -> app server -> database where the app server is frequently php-fpm for php or unicorn for ruby. If you really want to use bash you can google 'bash cgi' and find plenty of examples then just use bash for your app server. This is not necessarily less stable or secure than writing code in php/ruby/perl/ect. That being said bash would not be a friendly language choice for writing a web app in and all the major players allow you to shell out to run commands, so you're likely better off letting a more established stack/framework handle some details and shelling out to any bash code you have written.

Paul Mooring
Operations Engineer
www.opscode.com

________________________________________
From: on behalf of Matt Graham
Sent: Sunday, June 23, 2013 7:45 AM
To: Main PLUG discussion list
Subject: Re: OT: How to embed or call a shell script in an html file?

From: joe@
> Now, my follow-up question is, how can I integrate this shell script
> into an html file as I hope to be able to use it in a web page?


This is *not* a good idea. Creating dynamic web pages with shell can be done,
but it's not one of the things that shell is designed for/good at. One way is
briefly described at http://httpd.apache.org/docs/2.2/howto/ssi.html . You
will have an easier time of it if you use something that's designed for
creating dynamic web pages, like mod_python or CGI-Perl or Ruby on Rails or
PHP.

> #!/bin/bash - This shell script that I have named "qsearch" now works.
>
> while (:) do
> echo -e "Press S to search >>> \c"; ans=`readin`; echo; case $ans in
>   [sS]) echo -e "Find what word? \c";read name1
>         echo -e "and what second word? \c";read name2
>         fgrep -y "$name1" q-hid | fgrep -y "$name2" > tempz
>         cls; echo -e "\nSearch word(s): $name1 $name2";
>         echo "Here are the first 10 results found:"; echo
>         head -10 tempz; echo;;
>   [qQ]) cls; echo; exit;;
>   *) cls; echo "Not a valid option."; echo;; esac done
> esac
> done


How is this working? If I paste the above into temp.sh and execute it, it
says "/bin/bash: - : invalid option". If I fix the interpreter line so it
says "#!/bin/bash" , it complains that readin and cls are not valid bash
commands. If I replace "ans=`readin`" with "read ans" and "cls" with "clear",
it fails with a syntax error because "esac done" is in there twice.

--
Matt G / Dances With Crows
The Crow202 Blog: http://crow202.org/wordpress/
There is no Darkness in Eternity/But only Light too dim for us to see

---------------------------------------------------
PLUG-discuss mailing list -
To subscribe, unsubscribe, or to change your mail settings:
http://lists.phxlinux.org/mailman/listinfo/plug-discuss
---------------------------------------------------
PLUG-discuss mailing list -
To subscribe, unsubscribe, or to change your mail settings:
http://lists.phxlinux.org/mailman/listinfo/plug-discuss