Get the App
SLTechnology News&Howtos  ›  Servers  › 

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

Shulou Source: shulou.com Published: 2022-06-02 21:53:49 10月13日 Update

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

Tags: Script character run string array process formula time face output example content function delimiter name actual hour sequence quotation mark form Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Huawei Microsoft MySQL Shulou Tech Info