Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 493837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:26:33+00:00 2026-05-13T05:26:33+00:00

I have this bash script whose job is to monitor a log file for

  • 0

I have this bash script whose job is to monitor a log file for the occurrence of a certain line. When located, the script will send out an email warning and then terminate itself. For some reason, it keeps on running. How can I be sure to terminate bash script below:

#!/bin/sh

tail -n 0 -f output.err | grep --line-buffered "Exception" | while read line
do
    echo "An exception has been detected!" | mail -s "ALERT" monitor@company.com
    exit 0
done
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T05:26:34+00:00Added an answer on May 13, 2026 at 5:26 am

    You are opening a subshell in the while read and that subshell is who is exiting, not the proper one.

    Try before entering the while loop:

    SHELLPID=$$
    

    And then in the loop:

    kill $SHELLPID
    exit 0
    

    Or change your loop to not use a subshell.

    Since the parent script is always going to be in the tail -f which never ends I think you have no other choice than killing it from the inner subshell.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this line in a useful Bash script that I haven't managed to
I have a variable in my bash script whose value is something like this:
I'm using bash. Suppose I have a log file directory /var/myprogram/logs/ . Under this
I have this bash script which pases a text file and I would like
I'have a bash script calling a jar file like this: awk -f fileformat.awk list.txt
Let's imagine I have a bash script, where I call this: bash -c some_command
I have a bash script that has this function in it: function start_vi() {
I have a bash script that looks like this: #!/bin/sh previousRelease=`git describe --tags --match
For testing purposes I have this shell script #!/bin/bash echo $$ find / >/dev/null
I have a script that looks like this #!/bin/bash function something() { echo hello

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.