Suppressing the terminated message from pkill & killall commands in a bash script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Suppressing the terminated message from pkill & killall commands in a bash script
# 1  
Old 03-16-2011
Suppressing the terminated message from pkill & killall commands in a bash script

Hi all,

I've been pulling my hair out with this problem for 3 daysSmilie now without success any help would be massively appreciated.

Basically the script is used to shutdown a rails server so a new IP address can be assigned, the shutdown part is taken care of in function_one using the "pkill master" command. Once the server has been shutdown function_two is supposed to run and restart the server.

The problem is the when "pkill master" is run and the processes are killed the script is broken by the terminated message and function two never gets called. I understand that the terminated message is not coming from STDOUT or STDERR and that it is being generated by the shell's job control mechanism so I cant redirect to /dev/null or use 2>/dev/null to redirect the message.

I'm at my wits end I can not find a way to "pkill master" or "killall -q -r master" without generating the terminated message. Thanks in advance.



Code:
#!/bin/bash

function_one(){
if pgrep ruby > /dev/null | pgrep master
  then
      pkill master
      sleep 5
      function_two  
     
  else
       function_two  
    fi
}

function_two(){
    Do Stuff
}
function_one

# 2  
Old 03-17-2011
Execution should not affect with the messages.
What are the Messages?

Last edited by clx; 03-17-2011 at 12:30 AM..
# 3  
Old 03-17-2011
Quote:
Originally Posted by anchal_khare
Execution should not affect with the messages.
What are the Messages?
Sorry I should have included it

Quote:
/home/qbuntu/startup/init.bash: line 20: 7325 Terminated $filepath/master_startup.bash
PID, Signal that caused death: 7398, 9867073182236687 ((null))
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

Hpux pkill,a little help with script

This work #!/usr/bin/sh COMM=${1} shift UNIX95=1 ps -C ${COMM} -o pid='' | while read P do kill -15 ${P} done This don't work #!/usr/bin/sh COMM=${1} shift UNIX95=1 ps -C ${COMM} -o pid='' | while read P do kill -"$@" ${P} done (7 Replies)
Discussion started by: Linusolaradm1
7 Replies

2. UNIX for Advanced & Expert Users

script & issues with non-AIX commands

I need to capture lengthy screen puts and direct to .txt. Script command is started on Wed Aug 22 13:27:36 EDT 2012. # qcp sh: qcp: not found. An issue I have is that script command doesn't take non-AIX commands. I need to run application-specific commands and capture the output in... (2 Replies)
Discussion started by: Daniel Gate
2 Replies

3. Shell Programming and Scripting

Suppressing carriage return in bash alias

I'd like to create an alias that displays my string but leaves my cursor at the end. Not seeing any examples of this. One indirect way might be to preload or stuff the history buffer, so I just hit up arrow. (2 Replies)
Discussion started by: tns1
2 Replies

4. Shell Programming and Scripting

Suppressing a message from being displayed

I have a script which checks for *.txt files in a particular directory and if no files were found then it goes into sleep for 10 secs and looks back for files again and if any files were found then the script does some processing with the files found, which is my requirement too. FILE_EXISTS=`ls... (5 Replies)
Discussion started by: vpv0002
5 Replies

5. Red Hat

Suppressing Error Message is not working

I need to suppress the error message for commands. I have given the command like below lsb_release -dr 2>/dev/null But it is not working. Am testing with Red Hat Linux release 9. Guide me. Thanks in advance (2 Replies)
Discussion started by: forumguest
2 Replies

6. UNIX for Advanced & Expert Users

How would I create a NULL terminated file in Unix under Bash?

I am testing some file routines against potential "nasty name" Unix files, such as those with a CR, LF, in the middle or NULL terminated, utf multi-byte character. So, under Bash, I want some way of: mv "name" "name\0" with the \0 a real NULL. Against all my efforts, I have not been... (2 Replies)
Discussion started by: drewk
2 Replies

7. UNIX for Dummies Questions & Answers

BASH script that sends text message or email

Hi, I have a BASH shell script that batch processes data. I often start this script before I leave to go home for the day, and leave it processing over night. It has come to my attention that it would be very useful for me to add the capability of making the script notify me about certain things... (2 Replies)
Discussion started by: msb65
2 Replies

8. UNIX for Dummies Questions & Answers

suppressing an error message using the "ls" command

hi I'm new here so my question maybe be retarded or out of place: Is there a way to suppress the "No such file or directory" error message when using the "ls" command ? thanks (5 Replies)
Discussion started by: basher400
5 Replies

9. Shell Programming and Scripting

Killall script?

I am doing some system tuning and figuring out how to write a script that will kill multiple processes or all processes with the same owner. Can someone help me out? Thanks (5 Replies)
Discussion started by: nmajin
5 Replies

10. UNIX for Advanced & Expert Users

How to supress a "Killed" message when a process is terminated?

Does anyone know how I can supress the "Killed" message that's produced when I kill a process? I've got a script that performs a "tail -f" on a database error log and pipes the output into an awk script which looks for certain error messages and forwards any that qualify to my pager. The problem... (2 Replies)
Discussion started by: kenwolff
2 Replies
Login or Register to Ask a Question