linux 查看san链路状态,写个shell脚本 - 跟踪下链路状态

通过命令netstat获取链路状态,保存到/tmp下一个文件中。通过添加计划任务周期性获取链路信息。可以手动添加链路信息,可以删除保存的链路状态。还可以任意查看最近三次保存的信息。

获取所有保存的信息:$ vlinkstatus -a

获取最近一条、两条、三条保存的信息$ vlinkstatus -r

$ vlinkstatus -r 2

$ vlinkstatus -r 3

获取最近脚本帮助信息、版本信息$ vlinkstatus -h

$ vlinkstatus -v

vlinkstatus-1.2.sh

手动写入信息、清除保存的信息$ vlinkstatus -w

$ vlinkstatus --clear

脚本“vlinkstatus-1.2.sh”代码如下:#!/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 <

Usage: vlinkstatus [OPTION] [PARAMETER of read|r]

View the link state information.

Mandatory arguments to long option are mandatory for short options too.

-r, --read

read reslut from tmp file tailed.

read the last set of data by default. Allows up to 3 sets of data to be read.

-a, --all

read reslut from tmp file.

--edit

edit temporary file.

-v, --version

display version.

-w, --write

write reslut to tmp file.

--clear

delete the temporary file.

-h, --help

display this help and exit

E-mail bug reports to: <773805731@qq.com>

EOF

}

case $1 in

-w|--write)

write_it

;;

-r|--read)

read_itTail $2

;;

-a|--all)

read_itAll

;;

--edit)

edit_tmpFile

;;

--clear)

clear_it

;;

-v|--version)

view_version

;;

*)

view_help

;;

esac

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值