0

When I run client.sh script no output is coming. And when I use "system" command in php the client.sh script is running in infinite loop.

Server.sh: code:

#!/bin/bash

while : 
do
        printf "Do you want to continue:[Y/N]\n"
        read ans
        case $ans in
                "Y")continue;;
                "N")echo "Thank you"
                    exit 0;;
                "*")echo "Wrong choice"
                   continue;;
        esac
done

Output:

srikanth@localhost:~/www/phpshell$ ./scm.sh
Do you want to continue:[Y/N]
Y
Do you want to continue:[Y/N]
N
Thank you

Calls.php: Code:

<?php
$cmd="/home/srikanth/phptest/server.sh";
pcntl_exec($cmd);
?>

Output:

srikanth@localhost:~/phptest$ php calls.php 
Do you want to continue:[Y/N]
Y
Do you want to continue:[Y/N]
N
Thank you

Client.sh code:

#!/bin/bash
curl http://cxps103/svnadmin/calls.php

Output:

srikanth@localhost:~/phptest$ ./client.sh

Any suggestion would be of much help. Thank you.

Update:

As per Ibu's suggestion am simplifying my question, I had got the problem, there is a while loop in my server.sh script which causing a problem,

7
  • 2
    Wow this a lot to read, how about you write only the part that is having a problem Commented May 24, 2011 at 5:08
  • @lbu, I am having a problem only with client.sh script which is not showing any output on the terminal. Request to let me know how can I call the calls.php script. Thanks in advance Commented May 24, 2011 at 5:31
  • If you don't have a webserver running then the "curl" is pretty meaningless. Commented May 24, 2011 at 7:12
  • 1
    Err, what do you expect? That the bash script will run, display the menu and ask for your choice in a webbrowser? If that's the case, guess again, because it will never work as-is. Commented May 24, 2011 at 7:54
  • 2
    Why are you trying to run this through a web request (using curl)? As I said : this will never work, and it doesn't make any sense. If you want to run an interactive bash script on a remote server use SSH. Commented May 24, 2011 at 8:02

1 Answer 1

1

When the CGI script (server.sh) runs, its standard input is not connected to anything. Therefore the read command always sets ans to an empty value, which doesn't match any of the alternatives in the case statement, and the script loops forever.

As wimvds and others have remarked, your approach is fundamentally wrong. A CGI script generates an HTML page to display in a browser. It acts based on a client request. Once the script has its arguments, it doesn't get input from anywhere (unless it opens files on the server). Interaction for a web application consists of the user entering data in a form and pressing a submit button. Unix interactions such as entering input on stdin and seeing output on stdout don't work over HTTP.

Aside: the "*") case would only match a line consisting of a single * character. You probably meant *), meaning to match anything.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for correcting me. I will use the SSH method to generate interactive bash script. Thanks once again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.