That tries to connect to port 1521 on localhost. If there's no program
listening there, you get "connection refused".
I don't think what you want to do can be achieved with bash alone (if that's
not correct, hopefully more knowledgeable users will correct me). I think
that doing what you want requires some external utility, like eg netcat.
--
echo 0|sed 's909=oO#3u)o19;s0#0ooo)].O0;s()(0bu}=(;s#}#.1m"?0^2{#;
s)")9v2@3%"9$);so%op]t(p$e#!o;sz(z^+.z;su+ur!z"au;sxzxd?_{h)cx;:b;
s/\(\(.\).\)\(\(..\)*\)\(\(.\).\)\(\(..\)*#.*\6.*\2.*\)/\5\3\1\7/;
tb'|awk '{while((i+=2)<=length($1)-18)a=a substr($1,i,1);print a}'
inetd or xinetd are relatively easy ways of getting a bash script
listening on a port. With them, you can make your bash script run once
for each connection - and you don't need to deal with any socket API's -
just the usual stdin/stdout work fine.
Or another way, which is similar to netcat but written in a scripting
language itself, is my pnetcat program:
http://stromberg.dnsalias.org/~strombrg/pnetcat.html
ISTR pnetcat being faster than netcat on gigabit networks at one time
(perhaps it's still true, dunno), because although pnetcat is in a VHLL,
it allows you to specify block sizes and TCP window sizes. In fact, I
wrote it when I was doing some (optically switched) gigE performance
testing - it was able to get over of 900 Megabits/second on a CPU that
wasn't that blazing with modest tuning.
vi /etc/inetd.conf
12345 stream tcp nowait root /usr/sbin/tcpd /bin/bash -i
restart inetd
But that might be dangerous because ther is an interactive root shell
listen on purt 12345.
cheers
Not bash alone.
Possibly helpful:
http://groups.google.com/group/comp.unix.shell/browse_thread/thread/92797eb340fe40dd
I don't think that's available on Solaris 10. Sorry for not including
the platform on my OP.
Also I do not have access to inetd.conf as I am not the administrator on
the box in question.
Does the box have an internet connection?
> Maxwell Lol wrote:
>> Chuck <chuckh19...@gmail.com> writes:
>>
>>> Is there a way to get a bash script to listen for connections on a tcp
>>> port? I've tried "< /dev/tcp/localhost/1521" but that just throws a
>>> "connection refused" error. Thanks
>>
>> You can use the netcat program.
>>
>> nc -l -p portnumber | script
>>
>
> I don't think that's available on Solaris 10. Sorry for not including
> the platform on my OP.
Why is that a problem?
It's open source and should compile on Solaris.
Downlaod from
http://osdn.dl.sourceforge.net/sourceforge/netcat/netcat-0.7.1.tar.gz
AFAIK You don't need special priviledges to run it as long as it's not using
a reserved port.
Download it, unzip it. Type
./configure CC=/usr/local/bin/gcc (or whatever)
make (or gmake)
and you are set. Unless you don't have any compilers on your machine....
>>> You can use the netcat program.
>>>
>>> nc -l -p portnumber | script
>>>
>>
>>I don't think that's available on Solaris 10. Sorry for not including
>>the platform on my OP.
>
> Does the box have an internet connection?
Or a USB drive, CDROM, .....
No but I can pull stuff down to my workstation and upload it with scp.
>
> Download it, unzip it. Type
>
> ./configure CC=/usr/local/bin/gcc (or whatever)
> make (or gmake)
>
> and you are set. Unless you don't have any compilers on your machine....
>
I believe so. It's an Oracle DB server and IIRC the Oracle installer
requires cc and make to link it's binaries with only the options you select.
Does that work with the dixie-cups-and-strings method of communication?
Or does it use the internet like most versions of scp do?
Any network program - scp or otherwise - can only use the internet if
the host is connected to it.
I think you are confusing tcp/ip with the internet. TCP/IP is a suite of
protocols that can be used on any network. The internet is a network.
Solaris has Perl, how about doing some socket programming :
http://www.tutorialspoint.com/perl/perl_socket.htm
Solaris got dtrace and with bash you can useit very well
> Solaris got dtrace and with bash you can useit very well
How would I use it to set up a listener on a port that just does
something trivial like pass back "hello" if someone tries to connect to it?