How to detect key press in cgi shell script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to detect key press in cgi shell script?
# 1  
Old 12-07-2012
Question How to detect key press in cgi shell script?

I want to detect key pressed in my .cgi web page, but it does not work even I found the code in other web site.

My code is :

Code:
#!/bin/sh

#=================================================
#    PATH defination
# ================================================
DEFAULT_CONFIG=/etc/default_path
. ${DEFAULT_CONFIG}

if [ -r   $MAIN_CONFIG ]; then
        . $MAIN_CONFIG
else 
        echo "$MAIN_CONFIG not found !!!"
        exit 1
fi
#=================================================
#    Get external script function
# ================================================
#getData()
#
#    parameters:        $1 : variable name
#                        $2    : the filename to be get from
#
#    Return variable name: "getDataRtn" - return request of $1 value
#
#   i.e.    getData "LAN1_IFACE" $MAIN_CONFIG
#            answer=$getDataRtn
# 
if [ -r   ${WWW_SCRIPTS_LIB_PATH}/getData.sh ]; then
        . ${WWW_SCRIPTS_LIB_PATH}/getData.sh
else 
        echo "${WWW_SCRIPTS_LIB_PATH}/getData() not found !!!"
        exit 1
fi

#=================================================
#    Get display language
# ================================================
getData "LANGUAGE=" $MAIN_CONFIG
Language=$getDataRtn
    . ${WWW_MSG_PATH}/${Language}/DCapture
    . ${WWW_MSG_PATH}/${Language}/commsg
    
#=================================================
#    Main
# ================================================
echo "Content-type: text/html"
echo "Pragma: no-cache"
echo ""
echo "<HTML><HEAD>"
echo "<meta http-equiv=content-type content=text/html; charset=UTF-8>"
echo "<TITLE>$msg010</TITLE>"
. ${WWW_SCRIPTS_LIB_PATH}/style-init.sh
echo "</HEAD>"
echo "<BODY>"
ShowSubLogo "$msg010"

if [ "$CONTENT_LENGTH" != "" ]; then
    #if [ "$Stop" != "" ]; then
        killall tcpdump
        #ShowEndSucess "Capture Done!" "DCf_form"
    #fi    
fi
read -s -n 1 -p "Press any key to continue..."
echo "Test"
echo "<br> </br>"
echo "<br> </br>"
echo "<form name=DbC_form method=post action=DCapturefile.cgi>"
echo "<input name=Start value=\"$msg020\" type=submit>"
echo "<br> </br>"
echo "</form>"
echo "</BODY></HTML>"

The red word is what I found, but the result in the web page running is print Test,
that means: it skip the read operation?

So, is there has another way to detect pressing key down?

My purpose is :

Press any key to execute the shell script.

The whole process is:

Press "Start" button, and transfer to another .cgi web page.
The web page is do the shell script :
Code:
/fs1/tcpdump/tcpdump -c 20000 -s 1500 -w $filename &

and it works fine.
But I want to do another shell script when user want to stop capture tcpdump.
So, all the resolution I think are:
1. Detect key pressing, and if key pressed, do killall tcpdump.
2.There is a button in the .cgi web(html code), click button, and execute the shell script: killall tcpdump .

But I do not know how to press a button to do shell script as well.

Or is there has the other way?

Any help appreciated.
# 2  
Old 12-07-2012
CGI scripts run under HTTP and as such you cannot interact with them as you do with a standard script.

You could send a Javascript function to the client (web browser) that detected a key press and made a new request (HTTPRequestObject) to a separate script which returned the second part of your page, this response could then be set as the innerHTML of a div on the already loaded page.
This User Gave Thanks to Skrynesaver For This Post:
# 3  
Old 12-07-2012
Thanks! I will try again.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Run a command for specific amount of time with an auto key press

Hi, I have been trying to do a small fun project for myself. I want to run a command for 45 seconds. And to get the final output of this command, the script requires I push the "q" key on my keyboard and then the final output file becomes available. I tried the following script. But it... (12 Replies)
Discussion started by: jacobs.smith
12 Replies

2. Shell Programming and Scripting

Shell Script @ Find a key word and If the key word matches then replace next 7 lines only

Hi All, I have a XML file which is looks like as below. <<please see the attachment >> <?xml version="1.0" encoding="UTF-8"?> <esites> <esite> <name>XXX.com</name> <storeId>10001</storeId> <module> ... (4 Replies)
Discussion started by: Rajeev_hbk
4 Replies

3. Shell Programming and Scripting

Press Any Key script sequence using bash - HELP

hi to all. im a newbie in unix shell scripts. i want to make a simple unix shell script using the bash shell that asks a user to press any key after a series of commands, or an x if he wishes to exit. here's a sample script that i made: #!/usr/bin/bash pause(){ /usr/bin/echo "\t\t Press... (3 Replies)
Discussion started by: booghaw
3 Replies

4. Shell Programming and Scripting

Any key press causing logout from shell

Hi all! I have written a shell script which will invoke perl script infinitly in the background in a loop. Code will do as:Within while loop, perl script will be run in background, get the pid and notify pid in though mail. then wait for pid to be completed before going for next iteration. I am... (1 Reply)
Discussion started by: jramesh1
1 Replies

5. Shell Programming and Scripting

read -n1 -r -p "Press..." key / produces error in bash shell script

Hello! Sorry, for my not so perfect english! I want to stop bash shell script execution until any key is pressed. This line in a bash shell script read -n1 -r -p "Press any key to continue..." key produces this error When I run this from the command line usera@lynx:~$ read... (4 Replies)
Discussion started by: linuxinho
4 Replies

6. Shell Programming and Scripting

invoking a shell script inside cgi shell script

Hi, I have an HTML form through which I get some text as input. i need to run a shell script say script.sh inside a perl-cgi script named main_cgi.sh on the form input. I want to write the contents of the form in a file and then perform some command line operations like grep, cat on the text... (2 Replies)
Discussion started by: smriti_shridhar
2 Replies

7. Shell Programming and Scripting

Trap key press in a script

How can I trap a character press in the shell script. For eg:- I have a script runinng a infinite loops , I will need to quit if q is pressed. I have seen the traping the signal , but they give option only for traping the defined interrupt signals. But those does not help me here. (3 Replies)
Discussion started by: praveenbvarrier
3 Replies

8. UNIX for Dummies Questions & Answers

Capture an empty key press...

I am trying to test input from the user, if they press enter with out an Y or N. I have the characheter thing sorted but when it comes to a blank or empty key press I am having trouble. if ; then clear echo "Sorry, that is an invalid choice!" exit fi I am using a KSH script in... (3 Replies)
Discussion started by: jagannatha
3 Replies

9. Shell Programming and Scripting

Read line with a single key press...

I would really like to have a script that will accept the key press from the user with out having to press the enter key afterwards. i.e. echo "Press Y to print \c" read YesNo At this point the user has to press the enter key to continue. Is there a way to accept the key press from the... (3 Replies)
Discussion started by: jagannatha
3 Replies
Login or Register to Ask a Question