LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-09-2013, 11:31 PM   #1
srk2ola
LQ Newbie
 
Registered: Jan 2013
Posts: 2

Rep: Reputation: Disabled
nc command on shell is not working in background


hi all,

I have a sh script where I need to execute the nc command in the background (I need that nc still running after the script finish)

BUT Im seeing the nc command is executed but after a couple of seconds dissapear in the ps command

This is my script
Code:
#!/bin/sh
CURRENT_FILE="curfile.txt"
PID_FILE="file.pid"

> $CURRENT_FILE

java -jar javaApp.jar -file $CURRENT_FILE &
AV_PID=$!

nc -l 64001 >> $CURRENT_FILE &
NC_PID=$!

echo -e "$AV_PID \n $NC_PID" > $PID_FILE
Do you have ay idea why the nc is stopping working?
in the file.pid Im seeing both pids, but when I try the ps file, Im only seeing the pid of the javaApp.

Please help....
 
Old 01-10-2013, 01:59 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
A quick look here http://linux.die.net/man/1/nc suggests you may need the -k option as well?
 
Old 01-10-2013, 06:34 PM   #3
srk2ola
LQ Newbie
 
Registered: Jan 2013
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thanks,

With -k option didn't work.

I found my solution moving to socat... replace the line
Code:
nc -l 64001 >> $CURRENT_FILE &
with

Code:
socat -u TCP-LISTEN:64001,keepalive,reuseaddr,rcvbuf=131071 STDOUT >> $CURRENT_FILE &
Thanks
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] cd command not working in .cshrc file (bash shell SUSE Linux) jaili Linux - Newbie 3 05-30-2011 08:25 AM
cd command not working in .cshrc file(bash shell) in SUSE Linux jaili Linux User Groups (LUG) 2 05-30-2011 03:06 AM
cd command not working through variable in shell script neha_singhal Linux - Newbie 5 02-24-2010 09:04 AM
Getting shell command working through ruby?? wrapster Solaris / OpenSolaris 6 07-30-2008 11:36 AM
single command in shell script not working farkus888 Programming 5 04-01-2008 01:31 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration