Html run linux script

Running linux commands through html

I am successful to do this conversion in the terminal by using: The issue is how can I make the convert button in the html file run the script above to do the conversion and send the converted file back to the webpage . because I have to use plink to do the conversion. run html file from terminal how to open html file in terminal

Running linux commands through html

I want to create a basic html file that has an upload button for 3 files that are in a folder(.bed, .bim, .fam), and a convert button to convert those input files into another file (.ped, .map)

I am successful to do this conversion in the terminal by using:

plink --bfile inputFile --recode --out newFile 

The issue is how can I make the convert button in the html file run the script above to do the conversion and send the converted file back to the webpage . because I have to use plink to do the conversion.

Thanks and any help is much appreciated !!

There is no way to do this directly.

The closest you could come would be to run an HTTP server and write a server side program (e.g. via Perl + PSGI + FastCGI, Node.JS + Express or even Bash + CGI ) which acted as a wrapper around those commands.

You could then have an HTML document include a which, when submitted, would trigger the HTTP request that would cause the server to run that program.

Linux — How can I run a html file from terminal?, Navigate to the directory containing the html file. And Simply type the following on the Terminal:-. pushd .html; python3 -m http.server 9999; popd; Then click the I.P. address 0.0.0.0:9999 OR localhost:9999 (Whatever is the result after executing the above commands). Or type on the terminal :-. Usage examplebrowsername Feedback

How to Run HTML Code using Notepad in localhost

In this very #short video i will explain you how to run html , css file or code in localhost with notepad in chrome browser . This is very easy and helpful tu

Html to run a system command

I am trying to run this command to create a folder inside my raspberry pi but it isn’t working. I am not good with PHP or HTML. I googled and i am unable to solve, so posting it here. If it is repeated and the solution exists. please do provide me the link. TIA Code:

    if (isset($_POST['TestB'])) < shell_exec('sudo mkdir /www/test1'); >?>  
Test case 1 Test case 2

Have you noticed you are try to run a command with sudo , that means the user www-data must to be included in the /etc/ sudoers file .

I’ve tried your code, it works if i remove the ‘sudo’ and if i give permissions in the /www directory.

I think you need to configure the user in the sudoers file.

An example of my sudoers file:

#WWW-DATA User_Alias WEBUSER = www-data Cmnd_Alias CMDCOMMAND = /usr/sbin/asterisk, /sbin/iptables WEBUSER ALL = NOPASSWD:CMDCOMMAND #Allow members of group sudo to execute any command %sudo ALL=(ALL:ALL) ALL 

You need to replace the CMDCOMMAND, with the commands your webserver will run as root. In this case mkdir .

Читайте также:  Alt linux как установить принтер

Remember you need to go to /etc/ directory and use visudo -f sudoers to edit the sudoers file correctly.

P.S: If you want to test if your webserver could run a command, you can:

After it will be a sh console.

You could run your command before adding in code.

You can create a directory with PHP without calling out to the shell. PHP has its own mkdir function .

and do the same for the second mkdir command.

The first argument is the directory to create the second is the mode (permissions).

If you really want to create this directory in /www (see note about security below) you will need to edit the sudoers file for the www-data user as described in Ivan’s answer or create the directory and change the owner. You can create the /www directory with the following:

and change the ownership with the following:

Note: Giving www-data sudo privileges creates a security hole. You should probably create the directories you need in the /var/www/html/ directory where permissions are not an issue and sudo is not required. If you do not want these directories accessible from the web, I would suggest creating them in /var/www and changing the owner.

Running linux commands through html, The closest you could come would be to run an HTTP server and write a server side program (e.g. via Perl + PSGI + FastCGI, Node.JS + Express or …

Run html file from terminal

Linux — Html to run a system command, You need to replace the CMDCOMMAND, with the commands your webserver will run as root. In this case mkdir. Remember you need to go to /etc/ …

How to run an html file in terminal

how to open html file in terminal

Create an HTML file on your mac Open your terminal Run the command "open myFile.html" or navigate to it with Finder and right click > open with Brave See a search page load

Apache — How to run my html file with apache2, In my case where I have installed and running the Apache 2 and if I type localhost/ into the browser it opens the Apache 2 Ubuntu default Page.. Now …

Источник

Run a shell script with an html button

But no luck. Any suggestions? EDIT- Following slhclk’s and mit’s advice: I have a php file in /var/www that I point my web-browser to. The contents of the file is as follows:

If I type /home/aa/scripts/test.sh in shell, the script is able to execute. However, when I point my web-browser to http://example.com/screen.php (which has the code above), I see a blank page and the script hadn’t executed. Both have execute permissions. Why doesn’t it work?

It would be interesting to know what kind of web server this is. For example it could be a home linux server, a windows machine with XAMPP or a standard website mass hosting offer with a domain name from a big hoster?

This is really a Dup of this, even asked by same user»>> stackoverflow.com/questions/6235785/…, where I posted my working answer. Felt they should be linked.

5 Answers 5

What you are trying to do is not possible that way.

Note that there are always two sides to that: The client side and the server side. Is the script on the client computer or on the server?

If it’s on the client: You as the visitor are only seeing an HTML website. onClick will only be able to launch JavaScript (or other scripting languages), but not any arbitrary shell script that resides on your computer. HTML scripts only run in the browser and can only do limited things. Most importantly, they can’t interact with your computer.

Читайте также:  Настройка exim dovecot astra linux

Think about it: How would the browser know how to open the file? Don’t you think this would be a security issue as well – a plain website triggering the execution of scripts on a client’s computer? What if there was something like onClick(‘rm -rf /home/user’) ?

An alternative would be to run a Java applet, if you want code to be executed on the client, but this not exactly the same and it’s something really complicated. I don’t think it’s necessary to explain this in detail.

If the script is on the server: If you want to run a script on the server side and have the user trigger its execution, then you need to use a server side programming language. Just HTML won’t do it, because it’s more or less a static file. If you want to interact with the server, you could for example use PHP.

It has the exec function to run a command line script that is stored on the web server. So basically, you could write exec(‘/path/to/name.sh’); and it would run the script on the server.

However, just putting this into onClick is not enough here. If you don’t know about PHP and server side web programming yet, you might want to read a few tutorials first and then come back with a more specific question.

If you have a php file with the appropriate exec(. ) command, make sure the script has execute permissions set not only for the user but also for the group the web server is in, so in the simplest case just 777 .

In case of trouble check for the return value of the script with echo exec(. ); to see if there are any errors.

You can also run the script from the command line and not from the browser with php /path/to/file.php .

Источник

How to run Shell script from HTML?

I’m somewhat new to Ubuntu Linux. I need to run the shell script from a html code. As I read somewhere like using Apache2 to generate a html and somehow I’ve succeeded to run a sh file from html, but I’m unable to see the command prompt which executes the commands in the sh script. It’s running may be as a daemon. So can any body help me how to make it visible?

3 Answers 3

This is a totally wrong approach. The HTML file does nothing, it is a Markup language, that instructs a browser how to show you different elements. What you need it is a PHP, ASP, CGI, etc script that uses the system’s shell to run arbitrary commands.

thanks for the reply Frantique.. i’ve used ‘CGI’ only for this. but unable to view the output. is there any way we can make the terminal visible.

When you run a shell script as CGI, which is what I believe you are doing (or trying to do), it is run from the apache or other web server daemon and its output isn’t visible anywhere. You can redirect its output to a file, for example by replacing the original script with one that runs the script and saves the output:

#!/bin/bash ./original.sh | tee --append file-to-save-to 

(You should probably also update your question to show what your objective is, in addition to the problem you have encountered.)

Thanks for the reply otus, my intention is to make some build system with graphical user interface. rather than typing commands to build some code(ex: like make xxxx etc.) i want to create HTML buttons to be clicked for building appropriate module. But by using CGI i’m unable to see the output for ‘make’ and even i’m unable to know whether it is running background or not. so any one can help me regarding this.. is there any simple approach to follow other that what i’m using. thanks in advance

Читайте также:  Linux часы минуты секунды

outus, i’ve tried as u said to catch the output to some file, but the output is getting stored in the file only when every thing goes correct, if some error has occured (in the command mentioned in original.sh) then the file looks empty. -(

suresh, errors are written to stderr, so you’ll need to redirect that to either a different file or the same: e.g. ./original.sh 2>&1 | tee —append file

Источник

Run a shell script with an html button

As stated by Luke you need to use a server side language, like php. This is a really simple php example:

Save this as myfilename.php and place it on a machine with a web server with php installed. The same thing can be accomplished with asp, java, ruby, python, .

This answer works on my Ubuntu desktop with apache2 and php5 installed. Following is some additional information to help better understand this answer: 1. «myfilename.php» may be placed under the web server’s root directory (DocumentRoot) which usually is «/var/www». 2. «myfilename.php» contains the above code, plus other HTML code. 3. The web client uses «/myfilename.php» as the HTTP address.

we don’t php installed can it possible any other way like javascript. or without php install run this script.

Shell can also be a server-sided language. Why not just case «$/$» in (GET/run=true) /path/to/name.sh;; esac ? Then let web server software call this, I guess.

This is really just an expansion of BBB’s answer which lead to to get my experiment working.

This script will simply create a file /tmp/testfile when you click on the button that says «Open Script».

  1. The actual HTML Website with a button.
  2. A php script which executes the script
  3. A Script

The File Tree:

root@test:/var/www/html# tree testscript/ testscript/ ├── index.html ├── testexec.php └── test.sh 

1. The main WebPage:

root@test:/var/www/html# cat testscript/index.html 

2. The PHP Page that runs the script and redirects back to the main page:

root@test:/var/www/html# cat testscript/testexec.php 

3. The Script :

root@test:/var/www/html# cat testscript/test.sh #!/bin/bash touch /tmp/testfile 

if its possible to run the exe from sh file ? my environment is windows os. i want to execute the exe from browser i searched past three days nothing help me

Could you please expand on the need for ?success=true’ after the .html part on step 2? Maybe it can be removed?

PHP is likely the easiest.

Just make a file script.php that contains and send anybody who clicks the button to that destination. You can return the user to the original page with header:

This is how it look like in pure bash

#!/bin/bash echo Content-type: text/html echo "" ## make POST and GET stings ## as bash variables available if [ ! -z $CONTENT_LENGTH ] && [ "$CONTENT_LENGTH" -gt 0 ] && [ $CONTENT_TYPE != "multipart/form-data" ]; then read -n $CONTENT_LENGTH POST_STRING "|tr '&' ';'` fi eval `echo "$"|tr '&' ';'` echo "" echo "" echo "" echo "" if [[ "$vote" = "a" ]];then echo "you pressed A" sudo /usr/local/bin/run_a.sh elif [[ "$vote" = "b" ]];then echo "you pressed B" sudo /usr/local/bin/run_b.sh fi echo "" echo "
" echo "" echo "" echo "" echo "
" echo "
" echo "
" echo "
" echo "" echo ""

Источник

Оцените статью
Adblock
detector