Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

If the php script execution process does not exit within 30 minutes, kill these php script processes

2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

The online script reads as follows:

[root@localhost ~] # cat / data/scripts/check_php.sh

#! / bin/bashDate= `date "+% Y-%m-%d% H:%M:%S" `Num=$ (ps-ef | egrep "countjs_syc_site* | countjs_syc_plan* | countjs_syc.php | countjs_syc_img* | setcache*" | grep-v grep | wc-l) Pid=$ (/ bin/ps-ef | egrep "countjs_syc_site* | countjs_syc_plan* | countjs_syc.php | countjs_syc_img* | setcache*" | grep-v grep | awk'{print $2}') if [$Num-eq 0] Then echo "$Date No Process" > > / data/scripts/check_php.logelse for i in $Pid do echo "$Date Running Process $I" > > / data/scripts/check_php.log # # define Get Seconds varSec=$ (ps-p $I h-o etime | tail-1 | awk 'BEGIN {FS = ":"} {if (NF = = 2) {print $1x 60 + $2} else if (NF = = 3) {split ($1, a, "-") If (a [2]! = ") {print ((a [1] * 24yoga [2]) * 60 + $2) * 60 + $3;} else {print ($1x 60 + $2) * 60 + $3;}') if [$Sec-ge 1800] Then echo $Date > > / data/scripts/check_php.log ps-ef | grep $I | grep-v grep > > / data/scripts/check_php.log kill-9$ I echo "$Date $i The process runs for more than 30 minutes The process has been killed. "> > / data/scripts/check_php.log else echo" $Date $i The process runs in less than 30 minutes "> / data/scripts/check_php.log fi donefiecho'= ='> > / data/scripts/check_php.log

Another form of script is as follows:

Cat / root/scripts.awk

#! / usr/bin/awk-f BEGIN {FS = ":"} {if (NF = = 2) {print $1x 60 + $2} else if (NF = = 3) {split ($1, a, "-"); if (a [2]! = ") {print ((a [1] * 24yoga [2]) * 60 + $2) * 60 + $3;} else {print ($1x 60 + $2) * 60 + $3 }}}

The script is analyzed as follows:

Ps-ef | grep 18020 | grep-v grep | awk'{print $2}'; ps-p 18020 h-o etime | tail-1 | awk 'BEGIN {FS = ":"} {if (NF = = 3) {split ($1, a, "-"); if (a [2]! = ") {print ((a [1] * 24yoga [2]) * 60 + $2) * 60 + $3;} else {print ($10.060 + $2) * 60 + $3 }} 'echo "03:19:15" | awk' BEGIN {FS = ":"} {if (NF = = 3) {split ($0, a, ":"); if (a [1]! = ") {print a [1], a [2]}} 'echo" 03:19:15 "| awk' BEGIN {FS =": "} {if (NF = 3) {split ($0, a,": ") If (a [1]! = "") {print a [1], a [3]}}'ps-p 18020-o etime | tail-1 | awk 'BEGIN {FS = ":"} {if (NF = = 3) {split ($0, a, ":"); if (a [2]! = ") {print a [1], a [2], a [3]}; {print ($1x 60 + $2) * 60 + $3;}}' 03 54 0614046

Awk string handling function, split

Split uses fs as a separator to divide the s string into a sequence asplit can realize the array type segmentation of the string, which is illustrated by an example below. [root@localhost ~] # echo 'abcd'? | awk' {len=split ($0recom a, "); for (item1polii

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report