Advertisement
shiftdot515

hup

Oct 18th, 2017
533
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 19.71 KB | None | 0 0
  1. #! /bin/bash -norc
  2. # killprog allow user to kill a process by its command name, like killall
  3. ###Daniel###LaBell#2017#################################################<.>
  4. PATH=/bin:/usr/bin
  5. umask 077
  6. killprog(){
  7. #usage info
  8. if [ $# -lt 1 -o $# -gt 2 ];
  9. then
  10.     echo "usage: killprog [signum] progname"
  11.     echo "     will send a signal to all your processes whose name match progname"
  12.     echo "       defaults to -9"
  13.     echo "       ex. killprog netscape"
  14.     echo ""
  15.     echo "note: progname should not be a number"
  16.     exit 1
  17. fi
  18. #default sig
  19. SIG=-1
  20. # is $1 a number?
  21. test $1 -gt 0 2>/dev/null
  22. # if not above will barf with err=2,
  23. if [ $? -lt 2 ];
  24. then # is number
  25.    if [ $1 -lt 0 ]; # make sure it is neg.
  26.    then
  27.       SIG=$1;
  28.       shift
  29.    else
  30.       # its definite junk just, just shift
  31.       echo bad sig $1, using default $SIG
  32.       shift
  33.    fi
  34. fi
  35. if [[ -z "$1" ]]
  36. then
  37.     cat - >&2 <<EOF
  38. usage: killprog [signum] progname
  39. EOF
  40.     exit 0
  41. fi
  42. # see if $1 is a number
  43. test $1 -gt 0 2> /dev/null
  44. if [[ $? -lt 2 ]]
  45. then
  46.      #print mesg to stderr
  47.      cat - >&2 <<EOF
  48. This program may not function correctly
  49. if $1 is a process id number
  50. enter 'yes' to continue
  51. EOF
  52.      read ANS
  53.      if [[ "$ANS" != "yes" ]]
  54.      then
  55.           exit 1
  56.      fi
  57. fi
  58. set -x    
  59. for P in `ps -U $USER -o pid,ucomm | fgrep $1 | awk '{print $1}'` ;
  60.       do
  61.       echo kill $SIG $P ;
  62.       kill $SIG $P ;
  63.       done ;
  64. }
  65.  
  66. if [[ -z "$USER" ]]
  67. then
  68.     cat - >&2 <<'EOF'
  69. usage: hup [signum] prognam
  70. The environmental variable "$USER" is unset
  71. possible fixes:
  72.  USER=Johnny hup firefox
  73.  export USER=$LOGNAME
  74.  et cetera
  75.  fix login scripts so USER is set to what works for you
  76.  edit this script,  etc...
  77. EOF
  78.     exit 88
  79. fi
  80. killprog $*
  81. exit 0
  82. ############### end of program text ##########################
  83.  
  84.             GNU GENERAL PUBLIC LICENSE
  85.                Version 2, June 1991
  86.  
  87.  Copyright (C) 1989, 1991 Free Software Foundation, Inc.
  88.                           675 Mass Ave, Cambridge, MA 02139, USA
  89.  Everyone is permitted to copy and distribute verbatim copies
  90.  of this license document, but changing it is not allowed.
  91.  
  92.                 Preamble
  93.  
  94.   The licenses for most software are designed to take away your
  95. freedom to share and change it.  By contrast, the GNU General Public
  96. License is intended to guarantee your freedom to share and change free
  97. software--to make sure the software is free for all its users.  This
  98. General Public License applies to most of the Free Software
  99. Foundation's software and to any other program whose authors commit to
  100. using it.  (Some other Free Software Foundation software is covered by
  101. the GNU Library General Public License instead.)  You can apply it to
  102. your programs, too.
  103.  
  104.  When we speak of free software, we are referring to freedom, not
  105. price.  Our General Public Licenses are designed to make sure that you
  106. have the freedom to distribute copies of free software (and charge for
  107. this service if you wish), that you receive source code or can get it
  108. if you want it, that you can change the software or use pieces of it
  109. in new free programs; and that you know you can do these things.
  110.  
  111.  To protect your rights, we need to make restrictions that forbid
  112. anyone to deny you these rights or to ask you to surrender the rights.
  113. These restrictions translate to certain responsibilities for you if you
  114. distribute copies of the software, or if you modify it.
  115.  
  116.  For example, if you distribute copies of such a program, whether
  117. gratis or for a fee, you must give the recipients all the rights that
  118. you have.  You must make sure that they, too, receive or can get the
  119. source code.  And you must show them these terms so they know their
  120. rights.
  121.  
  122.  We protect your rights with two steps: (1) copyright the software, and
  123. (2) offer you this license which gives you legal permission to copy,
  124. distribute and/or modify the software.
  125.  
  126.  Also, for each author's protection and ours, we want to make certain
  127. that everyone understands that there is no warranty for this free
  128. software.  If the software is modified by someone else and passed on, we
  129. want its recipients to know that what they have is not the original, so
  130. that any problems introduced by others will not reflect on the original
  131. authors' reputations.
  132.  
  133.  Finally, any free program is threatened constantly by software
  134. patents.  We wish to avoid the danger that redistributors of a free
  135. program will individually obtain patent licenses, in effect making the
  136. program proprietary.  To prevent this, we have made it clear that any
  137. patent must be licensed for everyone's free use or not licensed at all.
  138.  
  139.   The precise terms and conditions for copying, distribution and
  140. modification follow.
  141.             GNU GENERAL PUBLIC LICENSE
  142.    TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  143.  
  144.   0. This License applies to any program or other work which contains
  145. a notice placed by the copyright holder saying it may be distributed
  146. under the terms of this General Public License.  The "Program", below,
  147. refers to any such program or work, and a "work based on the Program"
  148. means either the Program or any derivative work under copyright law:
  149. that is to say, a work containing the Program or a portion of it,
  150. either verbatim or with modifications and/or translated into another
  151. language.  (Hereinafter, translation is included without limitation in
  152. the term "modification".)  Each licensee is addressed as "you".
  153.  
  154. Activities other than copying, distribution and modification are not
  155. covered by this License; they are outside its scope.  The act of
  156. running the Program is not restricted, and the output from the Program
  157. is covered only if its contents constitute a work based on the
  158. Program (independent of having been made by running the Program).
  159. Whether that is true depends on what the Program does.
  160.  
  161.   1. You may copy and distribute verbatim copies of the Program's
  162. source code as you receive it, in any medium, provided that you
  163. conspicuously and appropriately publish on each copy an appropriate
  164. copyright notice and disclaimer of warranty; keep intact all the
  165. notices that refer to this License and to the absence of any warranty;
  166. and give any other recipients of the Program a copy of this License
  167. along with the Program.
  168.  
  169. You may charge a fee for the physical act of transferring a copy, and
  170. you may at your option offer warranty protection in exchange for a fee.
  171.  
  172.  2. You may modify your copy or copies of the Program or any portion
  173. of it, thus forming a work based on the Program, and copy and
  174. distribute such modifications or work under the terms of Section 1
  175. above, provided that you also meet all of these conditions:
  176.  
  177.    a) You must cause the modified files to carry prominent notices
  178.    stating that you changed the files and the date of any change.
  179.  
  180.    b) You must cause any work that you distribute or publish, that in
  181.    whole or in part contains or is derived from the Program or any
  182.    part thereof, to be licensed as a whole at no charge to all third
  183.    parties under the terms of this License.
  184.  
  185.    c) If the modified program normally reads commands interactively
  186.    when run, you must cause it, when started running for such
  187.    interactive use in the most ordinary way, to print or display an
  188.    announcement including an appropriate copyright notice and a
  189.    notice that there is no warranty (or else, saying that you provide
  190.    a warranty) and that users may redistribute the program under
  191.    these conditions, and telling the user how to view a copy of this
  192.    License.  (Exception: if the Program itself is interactive but
  193.    does not normally print such an announcement, your work based on
  194.    the Program is not required to print an announcement.)
  195. These requirements apply to the modified work as a whole.  If
  196. identifiable sections of that work are not derived from the Program,
  197. and can be reasonably considered independent and separate works in
  198. themselves, then this License, and its terms, do not apply to those
  199. sections when you distribute them as separate works.  But when you
  200. distribute the same sections as part of a whole which is a work based
  201. on the Program, the distribution of the whole must be on the terms of
  202. this License, whose permissions for other licensees extend to the
  203. entire whole, and thus to each and every part regardless of who wrote it.
  204.  
  205. Thus, it is not the intent of this section to claim rights or contest
  206. your rights to work written entirely by you; rather, the intent is to
  207. exercise the right to control the distribution of derivative or
  208. collective works based on the Program.
  209.  
  210. In addition, mere aggregation of another work not based on the Program
  211. with the Program (or with a work based on the Program) on a volume of
  212. a storage or distribution medium does not bring the other work under
  213. the scope of this License.
  214.  
  215.  3. You may copy and distribute the Program (or a work based on it,
  216. under Section 2) in object code or executable form under the terms of
  217. Sections 1 and 2 above provided that you also do one of the following:
  218.  
  219.    a) Accompany it with the complete corresponding machine-readable
  220.    source code, which must be distributed under the terms of Sections
  221.    1 and 2 above on a medium customarily used for software interchange; or,
  222.  
  223.    b) Accompany it with a written offer, valid for at least three
  224.    years, to give any third party, for a charge no more than your
  225.    cost of physically performing source distribution, a complete
  226.    machine-readable copy of the corresponding source code, to be
  227.    distributed under the terms of Sections 1 and 2 above on a medium
  228.    customarily used for software interchange; or,
  229.  
  230.    c) Accompany it with the information you received as to the offer
  231.    to distribute corresponding source code.  (This alternative is
  232.    allowed only for noncommercial distribution and only if you
  233.    received the program in object code or executable form with such
  234.    an offer, in accord with Subsection b above.)
  235.  
  236. The source code for a work means the preferred form of the work for
  237. making modifications to it.  For an executable work, complete source
  238. code means all the source code for all modules it contains, plus any
  239. associated interface definition files, plus the scripts used to
  240. control compilation and installation of the executable.  However, as a
  241. special exception, the source code distributed need not include
  242. anything that is normally distributed (in either source or binary
  243. form) with the major components (compiler, kernel, and so on) of the
  244. operating system on which the executable runs, unless that component
  245. itself accompanies the executable.
  246.  
  247. If distribution of executable or object code is made by offering
  248. access to copy from a designated place, then offering equivalent
  249. access to copy the source code from the same place counts as
  250. distribution of the source code, even though third parties are not
  251. compelled to copy the source along with the object code.
  252.  4. You may not copy, modify, sublicense, or distribute the Program
  253. except as expressly provided under this License.  Any attempt
  254. otherwise to copy, modify, sublicense or distribute the Program is
  255. void, and will automatically terminate your rights under this License.
  256. However, parties who have received copies, or rights, from you under
  257. this License will not have their licenses terminated so long as such
  258. parties remain in full compliance.
  259.  
  260.  5. You are not required to accept this License, since you have not
  261. signed it.  However, nothing else grants you permission to modify or
  262. distribute the Program or its derivative works.  These actions are
  263. prohibited by law if you do not accept this License.  Therefore, by
  264. modifying or distributing the Program (or any work based on the
  265. Program), you indicate your acceptance of this License to do so, and
  266. all its terms and conditions for copying, distributing or modifying
  267. the Program or works based on it.
  268.  
  269.  6. Each time you redistribute the Program (or any work based on the
  270. Program), the recipient automatically receives a license from the
  271. original licensor to copy, distribute or modify the Program subject to
  272. these terms and conditions.  You may not impose any further
  273. restrictions on the recipients' exercise of the rights granted herein.
  274. You are not responsible for enforcing compliance by third parties to
  275. this License.
  276.  
  277.   7. If, as a consequence of a court judgment or allegation of patent
  278. infringement or for any other reason (not limited to patent issues),
  279. conditions are imposed on you (whether by court order, agreement or
  280. otherwise) that contradict the conditions of this License, they do not
  281. excuse you from the conditions of this License.  If you cannot
  282. distribute so as to satisfy simultaneously your obligations under this
  283. License and any other pertinent obligations, then as a consequence you
  284. may not distribute the Program at all.  For example, if a patent
  285. license would not permit royalty-free redistribution of the Program by
  286. all those who receive copies directly or indirectly through you, then
  287. the only way you could satisfy both it and this License would be to
  288. refrain entirely from distribution of the Program.
  289.  
  290. If any portion of this section is held invalid or unenforceable under
  291. any particular circumstance, the balance of the section is intended to
  292. apply and the section as a whole is intended to apply in other
  293. circumstances.
  294.  
  295. It is not the purpose of this section to induce you to infringe any
  296. patents or other property right claims or to contest validity of any
  297. such claims; this section has the sole purpose of protecting the
  298. integrity of the free software distribution system, which is
  299. implemented by public license practices.  Many people have made
  300. generous contributions to the wide range of software distributed
  301. through that system in reliance on consistent application of that
  302. system; it is up to the author/donor to decide if he or she is willing
  303. to distribute software through any other system and a licensee cannot
  304. impose that choice.
  305.  
  306. This section is intended to make thoroughly clear what is believed to
  307. be a consequence of the rest of this License.
  308.   8. If the distribution and/or use of the Program is restricted in
  309. certain countries either by patents or by copyrighted interfaces, the
  310. original copyright holder who places the Program under this License
  311. may add an explicit geographical distribution limitation excluding
  312. those countries, so that distribution is permitted only in or among
  313. countries not thus excluded.  In such case, this License incorporates
  314. the limitation as if written in the body of this License.
  315.  
  316.   9. The Free Software Foundation may publish revised and/or new versions
  317. of the General Public License from time to time.  Such new versions will
  318. be similar in spirit to the present version, but may differ in detail to
  319. address new problems or concerns.
  320.  
  321. Each version is given a distinguishing version number.  If the Program
  322. specifies a version number of this License which applies to it and "any
  323. later version", you have the option of following the terms and conditions
  324. either of that version or of any later version published by the Free
  325. Software Foundation.  If the Program does not specify a version number of
  326. this License, you may choose any version ever published by the Free Software
  327. Foundation.
  328.  
  329.   10. If you wish to incorporate parts of the Program into other free
  330. programs whose distribution conditions are different, write to the author
  331. to ask for permission.  For software which is copyrighted by the Free
  332. Software Foundation, write to the Free Software Foundation; we sometimes
  333. make exceptions for this.  Our decision will be guided by the two goals
  334. of preserving the free status of all derivatives of our free software and
  335. of promoting the sharing and reuse of software generally.
  336.  
  337.                 NO WARRANTY
  338.  
  339.   11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
  340. FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
  341. OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
  342. PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
  343. OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  344. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
  345. TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
  346. PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
  347. REPAIR OR CORRECTION.
  348.  
  349.   12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
  350. WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
  351. REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
  352. INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
  353. OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
  354. TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
  355. YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
  356. PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
  357. POSSIBILITY OF SUCH DAMAGES.
  358.  
  359.              END OF TERMS AND CONDITIONS
  360.         How to Apply These Terms to Your New Programs
  361.  
  362.   If you develop a new program, and you want it to be of the greatest
  363. possible use to the public, the best way to achieve this is to make it
  364. free software which everyone can redistribute and change under these terms.
  365.  
  366.   To do so, attach the following notices to the program.  It is safest
  367. to attach them to the start of each source file to most effectively
  368. convey the exclusion of warranty; and each file should have at least
  369. the "copyright" line and a pointer to where the full notice is found.
  370.  
  371.     <one line to give the program's name and a brief idea of what it does.>
  372.    Copyright (C) 19yy  <name of author>
  373.  
  374.    This program is free software; you can redistribute it and/or modify
  375.    it under the terms of the GNU General Public License as published by
  376.    the Free Software Foundation; either version 2 of the License, or
  377.    (at your option) any later version.
  378.  
  379.    This program is distributed in the hope that it will be useful,
  380.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  381.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  382.    GNU General Public License for more details.
  383.  
  384.    You should have received a copy of the GNU General Public License
  385.    along with this program; if not, write to the Free Software
  386.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  387.  
  388. Also add information on how to contact you by electronic and paper mail.
  389.  
  390. If the program is interactive, make it output a short notice like this
  391. when it starts in an interactive mode:
  392.  
  393.    Gnomovision version 69, Copyright (C) 19yy name of author
  394.    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
  395.     This is free software, and you are welcome to redistribute it
  396.     under certain conditions; type `show c' for details.
  397.  
  398. The hypothetical commands `show w' and `show c' should show the appropriate
  399. parts of the General Public License.  Of course, the commands you use may
  400. be called something other than `show w' and `show c'; they could even be
  401. mouse-clicks or menu items--whatever suits your program.
  402.  
  403. You should also get your employer (if you work as a programmer) or your
  404. school, if any, to sign a "copyright disclaimer" for the program, if
  405. necessary.  Here is a sample; alter the names:
  406.  
  407.  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
  408.  `Gnomovision' (which makes passes at compilers) written by James Hacker.
  409.  
  410.   <signature of Ty Coon>, 1 April 1989
  411.   Ty Coon, President of Vice
  412.  
  413. This General Public License does not permit incorporating your program into
  414. proprietary programs.  If your program is a subroutine library, you may
  415. consider it more useful to permit linking proprietary applications with the
  416. library.  If this is what you want to do, use the GNU Library General
  417. Public License instead of this License.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement