Linux 工具命令
- 批量杀死进程
ps -ef | grep handle_clean_call | grep -v grep | awk '{print $2}' | xargs kill -9
- 查看网卡流量
network.sh
#!/bin/bash
ethn=$1
while true
do
RX_pre=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $2}')
TX_pre=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $10}')
sleep 1
RX_next=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $2}')
TX_next=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $10}')
RX=$((${RX_next}-${RX_pre}))
TX=$((${TX_next}-${TX_pre}))
if [[ $RX -lt 1024 ]];then
RX="${RX}B/s"
elif [[ $RX -gt 1048576 ]];then
RX=$(echo $RX | awk '{print $1/1048576 "MB/s"}')
else
RX=$(echo $RX | awk '{print $1/1024 "KB/s"}')
fi
if [[ $TX -lt 1024 ]];then
TX="${TX}B/s"
elif [[ $TX -gt 1048576 ]];then
TX=$(echo $TX | awk '{print $1/1048576 "MB/s"}')
else
TX=$(echo $TX | awk '{print $1/1024 "KB/s"}')
fi
#clear
time=`date +"%Y-%m-%d %T"`
echo -e "$time $ethn 下载流量:$RX\t上传流量:$TX"
done
bash network.sh 网卡名称
- 使用 curl 测试网络
#!/bin/bash
cnt_pos=1
while true
do
echo "--------------- the $cnt_pos requet ------------"
echo "Start time: "`date +"%Y-%m-%d %H:%M:%S"`
t0=`date +%s`
req_url="https://www.baidu.com"
echo "$req_url"
curl -w "@./curl-cfg.txt" -X get -i --connect-timeout 200 -m 200 "$req_url"
t1=`date +%s`
let s_t2=t1-t0
if [ $s_t2 -gt 3 ]
then
break
fi
let cnt_pos=cnt_pos+1
sleep 1s
done
curl-cfg.txt
\n
remote_ip: %{remote_ip}\n
remote_port: %{remote_port}\n
local_ip: %{local_ip}\n
local_port: %{local_port}\n
http_code: %{http_code}\n
dns: %{time_namelookup}s\n
redirect: %{time_redirect}s\n
time_connect: %{time_connect}s\n
time_appconnect: %{time_appconnect}s\n
time_pretransfer: %{time_pretransfer}s\n
time_starttransfer: %{time_starttransfer}s\n
size_download: %{size_download}bytes\n
speed_download: %{speed_download}B/s\n
----------\n
time_total: %{time_total}s\n
\n