Shell script used to detect Processes
10:38:08 | category: centos | font size subscription
Script 1:
#! /Bin/sh
Program = XXXX # process name
Sn = 'ps-Ef | grep $ program | grep-V grep | awk '{print $2} ''# obtain the process port number
If ["$ {sn}" = ""] # If it is null, the process is not started.
Then
Nohup/home/Oracle/xxxx & # background Startup Process
Echo start OK!
Else
Echo running
Fi
Script 2:
#! /Bin/sh
PS-Ef | grep./fileserver>/dev/null 2> & 1 # detect process write/dev/null
If [$? -EQ 0] #0 is normal
Then
Echo logprocess run OK!
Else
Nohup/home/Oracle/xxxx &
Echo start OK!
Fi
Script 3:
#! /Bin/sh
Count = 'ps-Fe | grep "A. Out" | grep-V "grep" | WC-l'
If [$ count-LT 1]; then
/Root/SH/restart. Sh
Script 4:
Pname = "authd"
Pathname =/root/cauthd/build/
Length = 'ps-Ef | grep "$ pname" | grep-V grep | cut-B 49-200 | WC-C'
If test $ length-EQ 0
Then
CD $ pathname
Nohup $ pname>/dev/null
Script 5:
#! /Bin/bash
Echo "Enter the process name :"
Read Process
Echo "the process you are looking for is $ process, and you are looking ..."
PS> text1
Grep "$ process" text1
Declare-I A =$?
If [$ A-EQ 0]
Then
Echo "this process exists"
Else
Echo "this process does not exist"
Fi
Rm text1
Detect process CPU mem
[Code]
[Root @ test ~] # Ps aux | awk-v ofs = "\ t" 'In in {print "httpd"}/% mem | httpd/{print $3, $4 }'
Httpd
% CPU % mem
0.0 1.5
0.0 1.5
0.0 1.5
0.0 1.5
0.0 1.5
0.0 1.5
0.0 0.1
[/Code]
Obtain the current memory status of the shell script
#! /Bin/sh
While true
Do
Echo 'free | awk '{print $3} ''| awk' {print $2} '>
STR = 'cat'
Echo $ Str
Echo 'free | awk '{print $2} ''| awk' {print $2} '> B
TOT = 'cat B'
Echo $ tot
# Rc = 'expr $ str/$ tot'
Rate = 'echo "scale = 2; $ str/$ tot" | bc'
Echo $ Rate
Echo "-------"
Sleep 1
Done