grep

shell脚本的坑:grep匹配+wc取值 在脚本执行后的结果与手动执行结果不一致

谁说胖子不能爱 提交于 2020-01-16 09:27:32
打算在跳板机上写一个shell脚本,批量检查远程服务器上的main进程是否在健康运行中。 先找出其中一台远程机器,查看main进程运行情况 1 2 3 4 5 [root@two002 tmp] # ps -ef|grep main root 23448 23422 0 11:40 pts /0 00:00:00 grep --color=auto main [root@two002 tmp] # ps -ef|grep main|grep -v grep|wc -l 0 shell检查脚本如下 1 2 3 4 5 6 7 8 [root@two002 tmp] # cat /tmp/main_check.sh #!/bin/bash NUM=$( ps -ef| grep main| grep - v grep | wc -l) if [ $NUM - eq 0 ]; then echo "It's not good! main is stoped!" else echo "Don't worry! main is running!" fi 执行脚本 1 2 3 4 5 6 7 8 9 10 11 12 [root@two002 tmp] # sh -x /tmp/main_check.sh ++ grep main ++ grep - v grep ++ wc -l ++ ps

Too much arguments with grep at if

*爱你&永不变心* 提交于 2020-01-16 05:01:07
问题 I was trying to look for $allowtunnel string at my file. Based on: How to test if string exists in file with Bash shell? So now I've the following at my script: allowtunnel="PermitTunnel" if [ grep -Fxq $allowtunnel /etc/ssh/sshd_config ]; then Since at execution time it says "too much arguments", I was looking and found this: Bash script - too many arguments So I change it to: if [[ grep -Fxq $allowtunnel /etc/ssh/sshd_config ]]; then But now, It delivers me the next one: ./script_install.sh

weblogic access.log日志常见分析

随声附和 提交于 2020-01-16 03:10:24
1,查看apache进程: ps aux | grep httpd | grep -v grep | wc -l // ps aux是显示所有进程和其状态。 2,查看80端口的tcp连接: netstat -tan | grep "ESTABLISHED" | grep ":80" | wc -l 3,通过日志查看当天ip连接数,过滤重复: cat access_log | grep "19/May/2011" | awk '{print $2}' | sort | uniq -c | sort -nr 4,当天ip连接数最高的ip都在干些什么(原来是蜘蛛): cat access_log | grep "19/May/2011:00" | grep "61.135.166.230" | awk '{print $7}' | sort | uniq -c | sort -nr | head -n 10 5,当天访问页面排前10的url: cat access_log | grep "19/May/2010:00" | awk '{print $7}' | sort | uniq -c | sort -nr | head -n 10 6,用tcpdump嗅探80端口的访问看看谁最高 tcpdump -i eth0 -tnn dst port 80 -c 1000 | awk -F".

How to print 10 letters preceding every occurrence of a particular character?

无人久伴 提交于 2020-01-16 01:05:46
问题 Using grep , I can print all occurrences of the uppercase letter "Z" in my document. The output, however, will display the entire lines in which every "Z" in the document was found. I need to limit this to printing only the 10 letters appearing before every occurance of "Z". E.g., if the document has a line with "AAAABBBBBBBBBCCCCCCDDDDDDDZ", it will print "CCDDDDDDD", the 10 letters appearing before. If there are fewer than 10 letters prior to "Z", then nothing needs to be printed. If "Z"

全面监测网站信息

≡放荡痞女 提交于 2020-01-15 20:34:39
加检测: 1.ip ping curl wget 检测 192.168.11.1444 ping -c 1 -w 1 192.168.11.21444 2.ip 加 端口 telnet echo -e "\n" | telnet 192.168.11.2144 13000 | grep Connected 3.进程 ps aux|grep -v grep|grep nginx echo $? 4.log 基于状态码的检测: tail -n100 /home/iqiyi4logs/iq444iyi444.log|awk -F", '{ print $8}'|sort -nr|uniq -c 一共有什么状态 有几个 tail -n100 /home/iqiyi4logs/iq4iy44i.log|awk -F", '{ print $8}'|grep "200"|wc -l 200的状态有几个 基于单位时间段内请求的访问 如果次数未达kpi异常 报警 tail -n1000 /home/iqiyilogs/iqiyi.log|grep "14/Jan/2020:16:54"|wc -l 来源: https://www.cnblogs.com/djwhome/p/12198242.html

grep: search once for different pattern and output to several files

浪尽此生 提交于 2020-01-15 20:33:24
问题 Is it possible to tell grep to use different output files for every type of matching search string? I need to search all *.log recursively to find all "[ERROR]", "[WARN]" and "[ASSERT]". But I would like to have it separated in different output files. One output file for each search string. (without calling grep several times!) searching already works: (called from gmake) grep -nHr --include=*.log -e '\[ERROR\]' -e '\[WARN\]' -e '\[ASSERT\]' $(root_path) > $(root_path)/result.txt But due to

grep: search once for different pattern and output to several files

ぐ巨炮叔叔 提交于 2020-01-15 20:28:09
问题 Is it possible to tell grep to use different output files for every type of matching search string? I need to search all *.log recursively to find all "[ERROR]", "[WARN]" and "[ASSERT]". But I would like to have it separated in different output files. One output file for each search string. (without calling grep several times!) searching already works: (called from gmake) grep -nHr --include=*.log -e '\[ERROR\]' -e '\[WARN\]' -e '\[ASSERT\]' $(root_path) > $(root_path)/result.txt But due to

Remove lines containg string followed by x number of numbers

主宰稳场 提交于 2020-01-15 11:06:07
问题 Hello I want to remove lines from a csv which contain the string vol followed by 2 or more number. Examples data: 2454564, Stage Mechanics vol 4 8 9, 121545, 454545454 24545454, Dancing on ice vol 5, 454554, 45454545 5454545, Who is the man, 545456454, 4545454 8785648654, year of the Panda vol 89 12, 545454, 545454 Desired Output: 24545454, Dancing on ice vol 5, 454554, 45454545 5454545, Who is the man, 545456454, 4545454 I know I can use: cat $csv1 | grep -vi "vol" > $newcsv but obviously

Extract data between two tags

佐手、 提交于 2020-01-15 10:34:21
问题 After searching and reading extensively, I managed to get half of the work done. Here is the string: <td class='bold vmiddle'> Owner CIDR: </td><td><span class='jtruncate-text'><a href="http://3.abcdef.com/ip-3/encoded/czovL215aXAubXMvdmlldy9pcF9hZGRyZXNzZXMvNDIuMjI0LjAuMA%3D%3D">42.224.0.0</a>/12</span></td> I need to extract the 42.224.0.0 and /12 to make a 42.224.0.0/12 . Now I managed to get 42.224.0.0 by using: sed -n 's/^.*<a.href="[^"]*">\([^<]*\).*/\1/p' but I'm at a loss how to

Extract data between two tags

寵の児 提交于 2020-01-15 10:34:06
问题 After searching and reading extensively, I managed to get half of the work done. Here is the string: <td class='bold vmiddle'> Owner CIDR: </td><td><span class='jtruncate-text'><a href="http://3.abcdef.com/ip-3/encoded/czovL215aXAubXMvdmlldy9pcF9hZGRyZXNzZXMvNDIuMjI0LjAuMA%3D%3D">42.224.0.0</a>/12</span></td> I need to extract the 42.224.0.0 and /12 to make a 42.224.0.0/12 . Now I managed to get 42.224.0.0 by using: sed -n 's/^.*<a.href="[^"]*">\([^<]*\).*/\1/p' but I'm at a loss how to