Suppress a background message in Bash


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Suppress a background message in Bash
# 1  
Old 10-10-2011
Suppress a background message in Bash

I'm having trouble with part of this bash script in Linux where I respawn a new instance of script and kill the old one to prevent forking (Yes, I know 'exec' will not fork but this needs to be interactive) When the old instance is kill it pops up "Terminated!" in the middle of the new instance that's running. I've seen a lot of suggestions to answer this here but either I'm not doing it right, or they're all wrong.

Here's the problematic part of the code:
Code:
control_c()
{
   echo -e "Would you like to do something?\n"
   echo -e "Enter y or n: "
   read yn

    if [ "$yn" == "y" ]; then

      echo -e "\nDoing something...\n"
      

                if [ -n $sumvar ]; then

                        echo -e "\nDoing Something else...\n"
                                bash what.sh
                        else
                                bash what.sh
                        fi
                fi


    else
          exit 0
    fi
}

trap control_c SIGINT
trap "rm -f /var/run/mine.pid" EXIT

pid=/var/run/mine.pid

if test -e $pid
then
        kilt=$(awk 'NR==1' $pid)
        exec kill -15 $kilt 2> /dev/null
else
        echo $$ > $pid
fi

Any help much appreciated!
# 2  
Old 10-10-2011
What, exactly, are you trying to do? Smilie Not your code, your ultimate goal.
# 3  
Old 10-11-2011
Well, I've written a very basic IDS. Sorry for not posting the code in its entirety, but its over 200 lines. It might be a lot to sort through and I really don't want to show it until its finished away. This is the last part I'm on.

Any help would be much appreciated.
# 4  
Old 10-12-2011
Yes -- but what, exactly, are you trying to do?
# 5  
Old 10-13-2011
Trying to get the "Terminated" message to not display. Even though the new instance of the script keeps running, a message will pop up saying "Terminated" (caused by killing the old instance's pid) and then a new command prompt. If you wait a second the new instance will give more output, but I don't want it to look to the user that the script has crashed. That's basically all.
# 6  
Old 10-13-2011
Yes -- but what, exactly, are you trying to do?

Not one little short-term goal.

Not whatever manner you feel hellbent on accomplishing it with.

I only mean what, you are trying, to do. What function this script is supposed to accomplish. WHY you are killing processes in such a manner. Why you think this "prevents forking".

Until you explain that, your script isn't going to make much sense. I'm not sure it ever will -- it may need replacing, not minor fixes.

Also, please stop PMing me.
# 7  
Old 10-14-2011
Quote:
Yes -- but what, exactly, are you trying to do?
Don't know how explain it much better than the title of this thread. That's what I was trying to do. Make the message stop happening. With that the script would work and look fine. Sorry, I thought my explanations would make things clearer.

Quote:
WHY you are killing processes in such a manner. Why you think this "prevents forking".
Because when it forks it kills one of the 2 current processes. If you know a better way than this or using exec, by all means show me.

Quote:
Also, please stop PMing me.
Sorry, I could see I was having trouble explaining this to you. I thought sending you the entire code would let you see what I was talking about. It won't happen again.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash function to suppress warning message for specific text and display prompt

In the below bash function multiple variants are input and stored in a variable $variant, and each is written to an out file at c:/Users/cmccabe/Desktop/Python27/out.txt stored on a separate line. # enter variant phox2b() { printf "\n\n" printf "What is the id of the patient getting... (0 Replies)
Discussion started by: cmccabe
0 Replies

2. Shell Programming and Scripting

Suppress Error Message

How can I suppress a error message being given by awk command in bash shell? (2 Replies)
Discussion started by: Prachi Gupta
2 Replies

3. Shell Programming and Scripting

Background tasks in a loop (bash)

I am trying to use a loop to start tasks 0-3, running 0,1,2 in the background with &. FOLDSET=( 0 1 2 3 ) for FOLDSET in ${FOLDSET} do if ; then BACKGRD="&" else BACKGRD="" fi # start task $FOLDSET task1 -nogui -ni -p $PROJ \ epochs=$EPOS ... (3 Replies)
Discussion started by: LMHmedchem
3 Replies

4. Shell Programming and Scripting

bash tee and background threads

Running centos 2.6, I have a bash script in which I'd like to run a number of background threads in parallel, tee'ing the results of the entire script to one file, while tee'ing the result of each background thread to another. Here's what I'm doing, where the number of csv files control the... (1 Reply)
Discussion started by: heatlamp
1 Replies

5. Shell Programming and Scripting

Suppress "Where are you?" Message

biff n pdir=`pwd` # check for null parameter if ; then echo current directory $pdir ls -latr echo else p1=$1 #check for directory entry only if ; then pdir=$p1 echo current directory $pdir cd $pdir ls -latr echo #check for directory entry and file... (2 Replies)
Discussion started by: wtolentino
2 Replies

6. Shell Programming and Scripting

background processing in BASH

I have script 3 scripts 1 parent (p1) and 2 children child1 and child2 I have script 3 scripts 1 parent 2 children child1 child2 In the code below the 2 child processes fire almost Instantaneously in the background, Is that possible to know the status of pass/fail of each process... (12 Replies)
Discussion started by: jville
12 Replies

7. Linux

background processing in BASH

I have script 3 scripts 1 parent 2 children child1 child2 In the code below the 2 child processes fire almost Instantaneously in the background, Is that possible to know the status of pass/fail of each process "as it happens" ? In the present scenario although Child2... (5 Replies)
Discussion started by: jville
5 Replies

8. Shell Programming and Scripting

Suppress error message in shell script

Hi All this is a simple script #! /bin/bash FileCnt=`ls -lrt $DIR/* | wc -l` echo $FileCnt how could i escape the error msg if there are no files in $DIR ls: /home/sayantan/test/files/cnt/*: No such file or directory 0 Looking forward for a quick reply Regards, Newbie... (3 Replies)
Discussion started by: newbie07
3 Replies

9. Shell Programming and Scripting

Suppress error message in unzip

I'm creating a bsh shell to unzip a file from one directory into another. The directory that holds the zip files has zip files constantly being added to it, so I am testing it before it does the unzip and more. Right now my code looks like this: unzip -tq $ZIP_PATH/$ZIP_NAME >/dev/null if ... (5 Replies)
Discussion started by: skwyer
5 Replies

10. Shell Programming and Scripting

suppress bash's "Done" message

Hi, I'm running a background job in my bash script. But when the job quit, bash echos a message like "+ Done xterm". This is annoying. How can I suppress it? (5 Replies)
Discussion started by: momiji
5 Replies
Login or Register to Ask a Question