while死迴圈 無法執行

來源:互聯網
上載者:User

標籤:while死迴圈自動結束

這是一個很低級的錯誤:首先看我們指令碼的名字 tcpdump.sh ,然後再看我們需要殺死進程的名字 grep tcpdump,

grep選項會把當前執行的指令碼名字同樣的過濾出來 ,所以這個指令碼當執行完一輪操作以後,同樣的被kill掉了,所以無法形成死迴圈。

最簡單的解決辦法,把指令碼換個名字 OK!!

 

 

 

[root]#bash -x tcpdump.sh
+ int=1
+ one=2
+ ((  1 != 2  ))
+ sleep 1
++ date +%F-%H:%M:%S
+ STIME=2014-08-12-22:11:50
+ sleep 30
+ tcpdump -i eth0 -s 0 -w tcpdum.2014-08-12-22:11:50 host 192.168.1.23
tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
+ ps -ef
+ grep tcpdump
+ grep -v grep
+ awk ‘{print $2}‘
+ xargs kill -9
Killed

本文出自 “crush” 部落格,請務必保留此出處http://only013.blog.51cto.com/6979724/1539172

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.