[NTLUG:Discuss] Forking server in bash posible ? (fun hack ...noapparent val
gan hawk
ganhawk1 at hotmail.com
Wed Mar 31 11:25:27 CST 2004
Hi,
Yes it would run the jobs parallely, but it would keep spawning as many
process as it can and crash. We need to spawn only if nc accepts a
connection. So I was looking for a way to read signals in bash.
Thanks,
Ganesh
>
>Use the &.
>
>It starts a process and sends it to the background...
>
>-----Burton
>
> > -----Original Message-----
> > From: discuss-bounces at ntlug.org [mailto:discuss-bounces at ntlug.org]On
> > Behalf Of gan hawk
> > Sent: Wednesday, March 31, 2004 12:19 AM
> > To: discuss at ntlug.org
> > Subject: [NTLUG:Discuss] Forking server in bash posible ? (fun hack
> > ...no apparent value )
> >
> >
> > Hi,
> >
> > This is something that has no value but I have done to amuse myself. So
> > read on if you also want to waste some time ;)
> >
> > I am trying to learn perl and saw this perl script to create a
> > streaming MP3
> > server on perl monks. I wanted to do the same in bash and here is what I
> > came up with (see below)... Now I was wondering if it was
> > possible to make
> > it a forking server. Like listen and when some connection comes
> > in, fork or
> > spaw a child process to do the work and continue listening. I think its
> > possible with netcat but I cannot figure it out. Anyways if
> > someone can do
> > that it would be fun.
> >
> > #!/bin/bash
> > DIR=`pwd`
> > echo "BASH_MP3D - A Streaming MP3 Server in Bash "
> > echo "Generating Playlist .....Plz wait"
> > PLAYLIST=`find $DIR -name *.mp3`
> > #PLAYLIST=`ls *.mp3`
> > NUM=`echo $PLAYLIST | wc -w`
> > echo "done."
> > echo "Listening on 5700 ....."
> > {
> > while true
> > do
> > #get seconds for random number
> > rand=`date | cut -d ':' -f 3 |cut -d ' ' -f1`
> > let "rand += 1"
> > while [ "$rand" -gt "$NUM" ]
> > do
> > let "rand -= $NUM"
> > done
> > SONG=`echo $PLAYLIST | cut -d ' ' -f$rand`
> > #Now we play the random song SONG
> > echo "Playing $SONG ... " >& 2
> > echo "HTTP/1.0 200 OK";
> > echo "Content-Type: audio/x-mp3stream";
> > echo "Cache-Control: no-cache ";
> > echo "Pragma: no-cache ";
> > echo "Connection: close ";
> > echo "x-audiocast-name: BASH MP3 Server";
> > echo;
> > echo;
> > dd if=$SONG bs=1024
> > done
> > }| nc -l -p 5700
> >
> > _________________________________________________________________
> > Is your PC infected? Get a FREE online computer virus scan from McAfee®
> > Security. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
> >
> >
> > _______________________________________________
> > https://ntlug.org/mailman/listinfo/discuss
>
>
>_______________________________________________
>https://ntlug.org/mailman/listinfo/discuss
_________________________________________________________________
Get rid of annoying pop-up ads with the new MSN Toolbar FREE!
http://toolbar.msn.com/go/onm00200414ave/direct/01/
More information about the Discuss
mailing list