Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9301965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:08:55+00:00 2026-06-18T23:08:55+00:00

I made a simple script in bash to serve as a http proxy. #!/usr/bin/env

  • 0

I made a simple script in bash to serve as a http proxy.

#!/usr/bin/env bash

trap "kill 0" SIGINT SIGTERM EXIT  # kill all subshells on exit

port="6000"

rm -f client_output client_output_for_request_forming server_output
mkfifo client_output client_output_for_request_forming server_output  # create named pipes

# creating subshell
(
    cat <server_output |
    nc -lp $port |  # awaiting connection from the client of the port specified
    tee client_output |  # sending copy of ouput to client_output pipe
    tee client_output_for_request_forming # sending copy of ouput to client_output_for_request_forming pipe
) &   # starting subshell in a separate process

echo "OK!"

# creating another subshell (to feed client_output_for_request_forming to it)
(
    while read line;  # read input from client_output_for_request_forming line by line
    do
        echo "line read: $line"
        if [[ $line =~ ^Host:[[:space:]]([[:alnum:].-_]*)(:([[:digit:]]+))?[[:space:]]*$ ]]
        then
            echo "match: $line"
            server_port=${BASH_REMATCH[3]}  # extracting server port from regular expression
            if [[ "$server_port" -eq "" ]]
            then
                server_port="80"
            fi
            host=${BASH_REMATCH[1]}  # extracting host from regular expression
            nc $host $server_port <client_output |  # connect to the server
            tee server_output  # send copy to server_output pipe
            break
        fi
    done

) <client_output_for_request_forming


echo "OK2!"

rm -f client_output client_output_for_request_forming server_output

I start it in first terminal. And it outputs OK!

And in the second I type:

netcat localhost 6000

and then start entering lines of text expecting them to be displayed in the first terminal window as there is a cycle while read line. But nothing is displayed.

What is it that I’m doing wrong? How can I make it work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T23:08:56+00:00Added an answer on June 18, 2026 at 11:08 pm

    If no process is reading from the client_output fifo, then the background pipeline is not starting. Since the process that reads client_output does not start until a line is read from client_output_for_request_forming, your processes are blocked.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've made a simple bash script that need to keep it's super-user privileges throughout
I made a simple bash script to convert movies from .avi to .mp4 but
I'm currently learning PHP. I've made a simple script @ http://hash.techho.me , only thing
I've made a simple bash script for server admininstration and I cannot figure how
I made a simple jquery script to sort content of the page on clicking
I made a simple script that allows users to sort divs using up and
I made a simple script which finds the Square root of a number. The
I made a simple wxPython script that simply shows a window. When I run
I've made this simple logout script: <?php session_start(); $db_connect = mysql_connect('localhost', 'root', '*****'); if(!$db_connect)
I have made a simple chat script using jquery and AJAX but the huge

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.