4

I cannot see to hide the "killed" output from my script. Please help.

killall -9 $SCRIPT

I have tried:

killall -9 $SCRIPT >/dev/null 2>&1

and everyone redirect combination it seems. Thanks for the help.

* UPDATE *

The main script cannot run in the background. It outputs a bunch on information to the user while running. Thanks for the input though. Any other ideas?

Here is the desired output

HEV Terminated
administrator@HEV-DEV:~/hev-1.2.7$

Here is the current output:

HEV Terminated
Killed
administrator@HEV-DEV:~/hev-1.2.7$

Atomiklan
  • 5,164
  • 11
  • 40
  • 62
  • please edit your question to include a sample of the "killed" output you hope to avoid. Good luck. – shellter Dec 31 '13 at 17:52
  • Related: http://stackoverflow.com/questions/81520/how-to-suppress-terminated-message-after-killing-in-bash – user000001 Dec 31 '13 at 17:53
  • Don't use `-9`. It should not be necessary, and if it is, then `$SCRIPT` has a bug and should be fixed. – chepner Dec 31 '13 at 18:26
  • Also, see questions [8074904 (How to shield the kill output)](http://stackoverflow.com/questions/8074904/how-to-shield-the-kill-output) and [714855 (Suppress Notice of Forked Command Being Killed)](http://stackoverflow.com/questions/714855/suppress-notice-of-forked-command-being-killed). – Gordon Davisson Dec 31 '13 at 19:21

4 Answers4

4

It's not the script printing it, it's the shell. You can suppress it by putting it in the background and waiting for it to finish, redirecting the error from there:

./script &
wait 2>/dev/null
Kevin
  • 53,822
  • 15
  • 101
  • 132
1

It looks like this can be avoided if you execute the script (including the &) in a subshell:

$ ( ./script.sh & )
$ ps
  PID TTY          TIME CMD
14208 pts/0    00:00:00 bash
16134 pts/0    00:00:00 script.sh
16135 pts/0    00:00:00 sleep
16136 pts/0    00:00:00 ps
$ killall script.sh
$

If I execute it (without the subshell) like ./script.sh then I get the output

[1]+  Terminated              ./script.sh &>/dev/null
user000001
  • 32,226
  • 12
  • 81
  • 108
0

Try ...

(killall -9 $SCRIPT) 2>/dev/null

This executes the "killall" in a subshell and all output from that subshell is redirected, including the the "KILLED" output.

smokes2345
  • 190
  • 1
  • 12
0

Try killall -q,--quiet don't print complaints

killall -q -9 $SCRIPT
  • Please provide an explanation of your answer, and how it is different from the other 3 answers on this 7 year old question. – miken32 Jul 19 '21 at 19:13