首页 \ 问答 \ 根据存在的命令杀死Linux进程(Kill Linux processes based on commands present)

根据存在的命令杀死Linux进程(Kill Linux processes based on commands present)

我正在学习Linux并且需要编写一个shell脚本,只要在其上运行另一个命令就会终止所有进程。 我知道如何使用变量编写脚本,但似乎无法找到为命令执行此操作的方法。

我想我需要找到一种方法来评估命令是否为真,并将其用作if语句的条件。 但我尝试的任何东西都会返回错

Linux是我学习的第一个CS相关的东西,我绝对坚持这一步。 我试着寻找这个,但我不确定要写什么。

这是sh shell。

编辑:每当使用某个命令执行程序时,我需要脚本立即终止它。


I am learning Linux and need to write a shell script that will kill all processes whenever another command runs on it. I know how to write a script with a variable, but cannot seem to find ways of doing it for a command.

I would imagine that I need to find a way to evaluate if the command is true or not and to use that as the condition for an if statement. But anything I try returns errors.

Linux is the first CS related thing that I am learning and I am absolutely stuck at this step. I tried searching for this but am not quiet sure what to write.

It's the sh shell.

Edit: Whenever a program is executed with a certain command I need the script to terminate it right away.


原文:https://stackoverflow.com/questions/32935347
更新时间:2023-08-19 19:08

最满意答案

你可以使用grep \bword\b ,这是在bash解析反斜杠之后真的是grep bwordb

使用grep '\bword\b' (注意单引号)。


You are proabably using grep \bword\b which is really grep bwordb after bash parses the backslashes.

Use grep '\bword\b' (note the single-quotes).

相关问答

更多
  • 我想编写一个正则表达式,它匹配{A:"和之前",RC:之后的日期和字符串",RC: 你可以使用这个grep: grep -oP '(?<=A:").*?(?=",RC:)' file 0b87654nuy I wanted to write a regex that matches the date and string that comes after {A:" and before ",RC: You can use this grep: grep -oP '(?<=A:").*?(?=",RC:)' ...
  • {n}是重复计数,它恰好匹配左侧原子的n副本。 所以我们可以将这个表达式细分为以下部分: [0-9] {8} - match 8 digits 030 - match "030" exactly [0-9] {4} - match 4 digits 因此,此模式匹配包含"########030####"任何内容,其中每个#是0到9的数字。 如果它检查的字符串的形式是YYYYmmddHHMMSS ,似乎就是这种情况,这个模式似乎是为了匹配凌晨3点到凌晨3点10分之间 ...
  • 您可以在regeular表达式中使用OR模式。 尝试以下配置。 @type grep regexp1 level (ERROR|FATAL) You can use OR pattern in regeular expression. Try following configuration. @type grep regexp1 level (ERROR|FATAL)
  • 如果您的目标只是为了“lubuntu”,而不是“lubuntu-somethingelse”,那么您可以在之后添加一个空格: ps -eo pid,cmd | grep "qemu.*-name lubuntu " | grep -v grep | awk '{print $1}' 或者没有额外的命令: pgrep -f "qemu.*-name lubuntu " 编辑:如果你需要一些可靠和通用的东西,而不是你自己的脚本,那么解析命令行总是一个坏主意。 有太多事情可能出错。 由于您使用libvirt来 ...
  • 在unix上有一个实用程序可以删除char 13,'\ r'或^ M. 语法可能有所不同 dos2unix optionsList.txt dos2unix optionsList.txt optionsList.txt There is an utility on unix to remove char 13, '\r' or ^M. Syntax may vary dos2unix optionsList.txt dos2unix optionsList.txt optionsList.txt
  • 你可以使用grep \bword\b ,这是在bash解析反斜杠之后真的是grep bwordb 。 使用grep '\bword\b' (注意单引号)。 You are proabably using grep \bword\b which is really grep bwordb after bash parses the backslashes. Use grep '\bword\b' (note the single-quotes).
  • 你可以利用前瞻?= 。 v_neutral(?=\\s+vaux_neutral) ?=\\s+vaux_neutral :向前看是否有一个或多个空格后跟vaux_neutral v_neutral :如果满足前瞻条件,则匹配v_neutral 看看演示 you can make use of a lookahead ?=. v_neutral(?=\\s+vaux_neutral) ?=\\s+vaux_neutral: looks ahead to see if there is one or more ...
  • 假设没有任何尴尬的东西像在其中有逗号的字段(因为如果前8个字段中有这样的字段,则无法在没有完整的CSV识别工具的情况下处理文件),并且存在第9个字段(因此第7个字段)第8个字段后面都有逗号)然后: grep '^\([^,]*,\)\{6\}\([^,]*,\)\2' file.csv 第一位表示6个零或多个非逗号序列,每个逗号后跟一个逗号。 然后是第7个(可能是空的)字段及其尾随逗号; 然后又是同样的东西( \2 )。 $ cat file.csv a,b,c,d,e,f,g,g,i a,b,c,d,e ...
  • AWK 这个awk one-liner会有所帮助: awk 'NR==FNR{if(/explorer[.]exe/)d[++i]=NR;next} {for(x=1;x<=i;x++)if(FNR>=d[x]-1&&FNR<=d[x]+4)next}7' file file 看这个例子: kent$ cat f foo foo2 Rule: r1 Owner: Process explorer.exe Pid 1544 remove1 remove2 remove3 remove4 b ...
  • 不使用任何捕获组, > my.list<-list(a='ivw_2014_abc.pdf',b='ivw_2014_def.pdf',c='ivw_2014_ghi.pdf') > gsub("^.*_|\\..*$", "", my.list, perl=T) [1] "abc" "def" "ghi" Without using any capturing groups, > my.list<-list(a='ivw_2014_abc.pdf',b='ivw_2014_def.pdf',c='ivw ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)