Keith C. Perry on 11 Aug 2015 07:17:34 -0700


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] Need Help with a script for netcat


Have you tried wrapping it in a while loop?  Something along the lines of...


while [ 1 ]
do
 INFO=$(hostname | cut -c 4-7)_$(date +%Y%m%d)
 /usr/bin/netcat -l -n -p 6000 >> /tmp/smdr_$INFO
done


~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Keith C. Perry, MS E.E.
Owner, DAO Technologies LLC
(O) +1.215.525.4165 x2033
(M) +1.215.432.5167
www.daotechnologies.com


From: "steve fiedler" <a31modela@hotmail.com>
To: "Philadelphia Linux User's Group Discussion List" <plug@lists.phillylinux.org>
Sent: Tuesday, August 11, 2015 9:34:04 AM
Subject: Re: [PLUG] Need Help with a script for netcat


i did try the -d option, not a valid option in netcat v 1.1.  Could only find the -d option on a version for windows.

Thanks,
Steve

Date: Tue, 11 Aug 2015 09:21:19 -0400
From: jonathan@jdsnetwork.com
To: plug@lists.phillylinux.org
Subject: Re: [PLUG] Need Help with a script for netcat

Try adding -d option to netcat

On Aug 11, 2015 8:59 AM, "steve fiedler" <a31modela@hotmail.com> wrote:
I have been having an issue getting a script to work running netcat in the background.  I need to listen on a certain port for info coming from a PBX all day long.  The PBX is sending SMDR data we want to use . ( call length, # of rings, etc....)

I have a script that does nothing but listen on a port for this info and appends a file with this data.  If I run the script in the foreground, it runs all day and gives me exactly what I want.

If I run it in the background or as a daemon from /etc/init.d, it starts but then stops. If I do a ps -ef | grep for the process, the netcat proc is still running but nothing is listening

 I have tried everything I can think of to keep it running, nohup the main script and the netcat command inside the script, ampersands, verbose mode to get a log, nothing will allow this to run in the background. 

Here is the script I am running, its called get_smdr.sh
#!/bin/bash
INFO=$(hostname | cut -c 4-7)_$(date +%Y%m%d)
/usr/bin/netcat -l -n -p 6000 >> /tmp/smdr_$INFO
Thats it....  If I try to run just the netcat command from the command it will fail also.  The -d option is not valid on netcat V1.1.  There is a -w option that will set  timeout for connects and final net reads.  I thought about setting this to 82800 ( 23 hours) and see if that works.  I do need to kill this job overnight so I can tar up the file and move it. then could restart with a cron job.

Any thoughts?  Is there another way I can accomplish this strictly via the command line ?

Thanks very much for your thoughts,
Steve



___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug


___________________________________________________________________________ Philadelphia Linux Users Group -- http://www.phillylinux.org Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug

___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug
___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug