~ubuntu-branches/ubuntu/trusty/abs-guide/trusty-proposed

« back to all changes in this revision

Viewing changes to abs/kill-byname.sh

  • Committer: Package Import Robot
  • Author(s): Sandro Tosi
  • Date: 2012-06-03 10:57:27 UTC
  • mfrom: (1.2.6)
  • Revision ID: package-import@ubuntu.com-20120603105727-rm7frl4feikr2swm
Tags: 6.5-1
* New upstream release
* debian/watch
  - updated
* debian/abs-guide.lintian-overrides
  - updated for new upstream code
* debian/control
  - bump Standards-Version to 3.9.3 (no changes needed)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash
2
 
# kill-byname.sh: Killing processes by name.
3
 
# Compare this script with kill-process.sh.
4
 
 
5
 
#  For instance,
6
 
#+ try "./kill-byname.sh xterm" --
7
 
#+ and watch all the xterms on your desktop disappear.
8
 
 
9
 
#  Warning:
10
 
#  -------
11
 
#  This is a fairly dangerous script.
12
 
#  Running it carelessly (especially as root)
13
 
#+ can cause data loss and other undesirable effects.
14
 
 
15
 
E_BADARGS=66
16
 
 
17
 
if test -z "$1"  # No command-line arg supplied?
18
 
then
19
 
  echo "Usage: `basename $0` Process(es)_to_kill"
20
 
  exit $E_BADARGS
21
 
fi
22
 
 
23
 
 
24
 
PROCESS_NAME="$1"
25
 
ps ax | grep "$PROCESS_NAME" | awk '{print $1}' | xargs -i kill {} 2&>/dev/null
26
 
#                                                       ^^      ^^
27
 
 
28
 
# ---------------------------------------------------------------
29
 
# Notes:
30
 
# -i is the "replace strings" option to xargs.
31
 
# The curly brackets are the placeholder for the replacement.
32
 
# 2&>/dev/null suppresses unwanted error messages.
33
 
#
34
 
# Can  grep "$PROCESS_NAME" be replaced by pidof "$PROCESS_NAME"?
35
 
# ---------------------------------------------------------------
36
 
 
37
 
exit $?
38
 
 
39
 
#  The "killall" command has the same effect as this script,
40
 
#+ but using it is not quite as educational.