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

164
Views
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 answers
Answer question

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 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!