steve fiedler on 11 Aug 2015 05:59:03 -0700


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

[PLUG] Need Help with a script for netcat


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