11lxm 发表于 2018-8-27 10:22:32

写个shell脚本 - 跟踪下链路状态

#!/bin/bash  
# vlinkstatus-1.2.sh
  

  
TMPFILE="/tmp/.tmp_vlinkstatus.txt"
  
write_it () {
  
    echo "" >> $TMPFILE
  
    date +%F_%T >> $TMPFILE && echo "Write date information."
  
    netstat -4 -natup >> $TMPFILE && echo "Write state information."
  
}
  

  
clear_it () {
  
    rm -f $TMPFILE
  
}
  

  
# The first position parameter of the function is the second position
  
# parameter of the script.
  
# position parameter - show a few records, values allow 1,2,3.
  
#                      default is 1.
  
read_itTail () {
  
    declare tmp_datestamp=""
  
    declare -i k=1
  
    case $1 in
  
      2)
  
          k=2
  
          ;;
  
      3)
  
          k=3
  
            ;;
  
      *)
  
          k=1
  
          ;;
  
    esac
  
    tmp_datestamp="`vlinkstatus -a | grep "^[[:digit:]]\{4\}" | tail -$k | head -1`"
  
    sed -n '/'$tmp_datestamp'/,/$$/p' $TMPFILE
  
}
  

  
read_itAll () {
  
    cat $TMPFILE 2> /dev/null
  
}
  

  
edit_tmpFile () {
  
    vim $TMPFILE
  
}
  

  
view_version () {
  
    sed -n '/vlinkstatus/p' $0 | sed -n '1p' | cut -d# -f2
  
}
  

  
view_help () {
  
      cat
页: [1]
查看完整版本: 写个shell脚本 - 跟踪下链路状态