How can I execute a shell script from an html link?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How can I execute a shell script from an html link?
# 1  
Old 02-18-2010
How can I execute a shell script from an html link?

I want to execute a shell script when clicking on an html link. I want the output of the script to be shown on the webpage. Whats the best way to achieve this?
# 2  
Old 02-18-2010
Hi.

The simplest way is probably just to put the script into your cgi-bin directory.

You need something like this at the top of your script (after the shebang, but before echoíng anything else), otherwise you'll get a 500 error.

Code:
#!/bin/bash
echo "Content-type: text/html"
echo

and then have a link to the script in your web page:
i.e.
Code:
<a href="/cgi-bin/myScript.sh">Run Script</a>

# 3  
Old 02-18-2010
Not an expert but...

This sounds like a server-side issue
and you might want to consider either
perl, python or php.

A.
# 4  
Old 02-18-2010
Quote:
Originally Posted by ASGR
Not an expert but...

This sounds like a server-side issue
and you might want to consider either
perl, python or php.

A.
You don't need any of those things to execute a shell script from a Web Page.

So long as you send the right header information, you could write it in anything.

Besides, it wasn't an issue, only a question.

S.
# 5  
Old 02-19-2010
Thanks for the information guys.
# 6  
Old 02-25-2010
Hey guys, so I basically wrote a simple script that ssh's into different machines and grabs some info. However, the script isn't instantaneous with the output and it seems to give me a blank screen when I execute from a link.

My question is how can I make apache refresh the page, or wait till the script finishes, then display the output?
# 7  
Old 02-26-2010
Quote:
Originally Posted by streetfighter2
My question is how can I make apache refresh the page, or wait till the script finishes, then display the output?
You can use :

Code:
<META HTTP-EQUIV="Refresh"CONTENT="10; URL=http://abcde.com">

It will refresh to URL every 10 seconds
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Trying to execute a script to populate all directories with index.html

Hello, I am trying to create a php file that would copy given index.html file to all directories (and subdirectories) on my site that don't have one. This is to prevent directory listings on nginx. This index.html file is placed in the /populate directory and looks like this: <html> <head>... (7 Replies)
Discussion started by: teletubby
7 Replies

2. UNIX and Linux Applications

execute shell script using CGI for html site

hi there im currently in the process of creating a website for use basically within our org. im using a os x machine and installed MAMP - which includes Apache, mysql... the site will be used by techs to primarily install pkgs files onto os x devices. i would like to have buttons or hyperlinks... (2 Replies)
Discussion started by: sheshe
2 Replies

3. Shell Programming and Scripting

Help to write a script or program to automatic execute and link input file data

Output file template format <input_file_name>a</input_file_name> <total_length_size>b</total_length_size> <log_10_length_size>c</log_10_length_size> Input_file_1 (eg. sample.txt) SDFSDGDGSFGRTREREYWW Parameter: a is equal to the input file name b is equal to the total length of... (2 Replies)
Discussion started by: perl_beginner
2 Replies

4. Shell Programming and Scripting

How to use ssh execute other shell script on other host (shell script include nohup)?

i want use ssh on the host01 to execute autoexec.sh on the host02 like following : host01> ssh host02 autoexec.sh autoexec.sh include nohup command like follwing : nohup /home/jack/deletedata.sh & after i execute ssh host02 autoexec.sh one the host01. i can't found deletedata.sh... (1 Reply)
Discussion started by: orablue
1 Replies

5. Web Development

Rewrite rules to change “link.html?hl=es” to “/es/link.html” etc?

Hey! Does anyone know how to create rewrite rules to change: “link.html?hl=en” to “/en/link.html” “link.html?hl=jp” to “/jp/link.html” “link.html?hl=es” to “/es/link.html” etc? Where "link.html" changes based on the page request? (2 Replies)
Discussion started by: Neo
2 Replies

6. Web Development

html link to images in /tmp directory

Because of permission issues, I need to link to images in my web page which are stored in /tmp which of course is located in the root directory but my actual html page is much further down in another directory. I thought the the following code should work, but the image comes up as a broken link:... (2 Replies)
Discussion started by: Solerous
2 Replies

7. Shell Programming and Scripting

Shell script -- symbolic link

Hi , pwd -P will give the physical directory name for symbolic names. is there any command to get the value of symbolic link ? if it's symbolic link , I have to get the physical directory name? any ideas to code in shell ? Thanks (3 Replies)
Discussion started by: talashil
3 Replies

8. Shell Programming and Scripting

Shell script to create a link

Hi All, I have a problem to writing a shell script to create a soft link in some other directory For eg: /opt/Shreedhar/Naik is directory now i need to write shell script in the path /opt/Shreedhar/Naik which should create a soft link in /opt/Shreedhar. I have tried to write the script... (3 Replies)
Discussion started by: Shreedhar Naik
3 Replies

9. Shell Programming and Scripting

needed very good link for Shell script

I am new to shell script.I need a link which explains basic concepts for shell scrpting (1 Reply)
Discussion started by: rajareddy_24
1 Replies
Login or Register to Ask a Question