0

I have a bash CGI logging connections to my server, I want to that when a new connection is requested/stablised/served this script passes an argument/variable to another script running in the background? is this possible? how can i do this?

I have tried environmental variables but this will only work in the same shell and I cannot be sure both will be running on the same shell. I've tried writing to a file but how could i know when the file has been edited thus allow the second script to execute the command.

I'm starting to get crazy, this must be possible I cannot believe to "programs" cannot share information... :O

maybe i'm taking the wrong approach, can someone please advise?

Thanks, Marco P.

1
  • Is the background script just hanging around waiting for input from the CGI script? Commented Apr 17, 2014 at 20:26

1 Answer 1

2

named pipes might be one way, although it is blocking:

setup:

mkfifo /path/to/named/pipe

cgi script:

echo "some data" > /path/to/named/pipe   # blocks until other script consumes!

background script:

while :; do
    read data < /path/to/named/pipe      # blocks until cgi script produces!
    do_stuff_with "$data"
done
Sign up to request clarification or add additional context in comments.

3 Comments

inotify-tools is another possibility so that the background script can wake up and do stuff when a new file arrives in a watched directory.
Thanks for your comment as a matter of fact I just found out about the fifo's always saw them around never checked them out, :P ill give it a try, also about inotify find it very interesting the only problem I see is that i have to run it and it doesn't give me the information until I end the command is there i was using inotifywatch (I think). How could I use it to get the info in real time? while comman running? hmmm fifo's again right? :P thanks a lot !
Thanks a lot! this worked beautifully... each day I love bash more and more, why do people still try to use compilers! xP I guess we need the to have Linux in the first place xD

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.