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:
#!/bin/bash
#
# Prompt the user to specify a daemon name and save the name to the variable n_prog
echo
"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 output
pro_file_name=status
not_connected=65
interval=2
# Search for the process Number of the daemon specified in the n_prog variable
pidno=$(
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 null
if
[ -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"
echo
fi
#
# 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
echo
done
exit
0
Run the ls command to test:
OVER ~~