Shell script used to detect Processes

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.