• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

174
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.

about 3 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

about 3 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
about 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error