Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

252
Views
bash ejecutando nc con ampersand termina el programa

Quiero ejecutar nc a través de & y luego alimentar manualmente los datos en stdin desde el sistema de archivos /proc cuando lo desee. entonces el problema es:

si ejecuto nc 127.0.0.1 1234 &

el programa se ejecuta en segundo plano y puedo escribir en stdin lo que quiera. pero, si creo test.sh y agrego

 #!/bin/bash nc 127.0.0.1 1234 & sleep 20

se conecta a 1234 y termina inmediatamente (ni siquiera espera 20 segundos). ¿por qué? Sospechaba que obtiene su stdin escrito desde algún lugar.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Si entiendo bien su propósito, desea enviar datos manualmente a nc que se enviarán al cliente.

Puede usar canalizaciones con nombre para este propósito.

cat /tmp/f | ./parser.sh 2>&1 | nc -lvk 127.0.0.1 1234 > /tmp/f

donde /tmp/f es una tubería hecha usando mkfifo /tmp/f

lo que quiera enviar a nc se puede repetir en parser.sh

over 4 years ago · Santiago Trujillo Report

0

Interesante pregunta.

La página de manual de bash dice:

 If a command is followed by a & and job control is not active, the default standard input for the command is the empty file /dev/null. Otherwise, the invoked command inherits the file descriptors of the calling shell as modified by redirections.

Si llama a nc 127.0.0.1 1234 < /dev/null fuera de un script de shell (con control de trabajo), obtendrá lo mismo.

Puede cambiar su script bash de esta manera para que funcione:

 #!/bin/bash nc 127.0.0.1 1234 < /dev/stdin & sleep 20
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!