Test Process status of shell script

Source: Internet
Author: User
Test the network connection status based on the running status of the daemon. This is far better than simply finding the network connection status parameters. The following uses a script to test the status of a specified process name and displays the test result to the standard output. Code :#! /B tests the network connection status based on the running status of the daemon. This is far better than simply finding the network connection status parameter. The following uses a script to test the status of a specified process name and displays the test result to the standard output.

Code:

  #!/bin/bash # # Prompt the user to specify a daemon name and save the name to the variable n_progecho "check up progress status"echo -n "Input a name of progress:"read n_prog # # Define constants to define the time interval between parameters that send test results to the standard outputpro_file_name=status not_connected=65 interval=2 # Search for the process Number of the daemon specified in the n_prog variablepidno=$( ps ax |grep -v "ps ax" |grep -v grep|grep $n_prog|awk '{print $1}') # echo "checkingfor \"$n_prog\",please wait..."echo# Determine whether the value of the variable pidno is nullif [ -z "$pidno" ]    then      echo "The status be stopped..."      echo "And belong to not connected"      echo      exit $not_connected    else      echo "The status is running..."      echo "And belong to connected"      echofi# # If the file corresponding to the specified process exists but the process is not connected, run the if structure statement.while [ true ]       do         if [ ! -e "/proc/$pidno/$pro_file_name" ]              then                echo "But he progress is disconnected"                echo                exit $not_connected          fi# Obtain some connection parameters and output them to the standard output    netstat -s |grep "packets received"    netstat -s |grep "packets delivered"# The time interval for displaying a parameter is defined by the variable $ interval.    sleep $interval     echodoneexit 0

Run the ls command to test:

 

OVER ~~

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.