⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 connect-stat.sh

📁 Shall高级编程
💻 SH
字号:
#!/bin/bashPROCNAME=pppd        # ppp daemonPROCFILENAME=status  # Where to look.NOTCONNECTED=65INTERVAL=2           # Update every 2 seconds.pidno=$( ps ax | grep -v "ps ax" | grep -v grep | grep $PROCNAME | awk '{ print $1 }' )# Finding the process number of 'pppd', the 'ppp daemon'.# Have to filter out the process lines generated by the search itself.##  However, as Oleg Philon points out,#+ this could have been considerably simplified by using "pidof".#  pidno=$( pidof $PROCNAME )##  Moral of the story:#+ When a command sequence gets too complex, look for a shortcut.if [ -z "$pidno" ]   # If no pid, then process is not running.then  echo "Not connected."  exit $NOTCONNECTEDelse  echo "Connected."; echofiwhile [ true ]       # Endless loop, script can be improved here.do  if [ ! -e "/proc/$pidno/$PROCFILENAME" ]  # While process running, then "status" file exists.  then    echo "Disconnected."    exit $NOTCONNECTED  finetstat -s | grep "packets received"  # Get some connect statistics.netstat -s | grep "packets delivered"  sleep $INTERVAL  echo; echodoneexit 0# As it stands, this script must be terminated with a Control-C.#    Exercises:#    ---------#    Improve the script so it exits on a "q" keystroke.#    Make the script more user-friendly in other ways.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -