Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

165
Visualizações
How to exit tail -f and resume script

I have a simple script, that sets up logging, runs tail -f on the log file and then, after I exit tail, performs some cleanup. Basically something like this

echo 'monitoring started'
tail -f /var/log/some.log
echo 'never gets here'

Problem is, exiting tail by Ctrl+C breaks the script execution too, so cleanup is not called. Is there a way to 'properly' exit tail and resume script call? I found a few solutions based on saving PID and killing it by timeout, but that's not what I want here, I may need the monitoring for a few minutes or few hours, so I'd like to have a manual switch.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You can do something like this

echo "monitoring started"
tail -f /var/log/some.log & #execute tail in background
read -sn 1 #wait for user input
kill %1 #kill the first background progress, i.e. tail
echo "Is reached"
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda