linux 服务器之间无密码传送文件
2014-10-31 14:21
671 查看
#!/bin/ksh
portalMSPort="8881"
localhostIP="172.21.11.97"
monitorProgramName=portalMS
monitorpath="/usr/local/portal/jboss5/bin/run.jar"
sysMonitorDataFile="/usr/local/portalMS/jboss5/bin/sysMonitorData.txt"
###监控进程类型:0:java 1:c
monitorType=0
getCPUUseRatio()
{
times=5
cpuIdleInfo=`top -b -n $times | grep 'Cpu(s)' | awk -F' ' '{print $5}'`;
i=0;
total=0;
for eachInfo in $cpuIdleInfo
do
i=`expr $i + 1`;
#first rows not get
if [ "X$i" == "X1" ]; then
continue;
fi;
eachIdle=`echo $eachInfo | cut -d"%" -f1`;
flag=`echo $eachInfo | cut -d"%" -f2`;
if [ "X$flag" == "Xid," ]; then
total=`echo $total + $eachIdle | bc`;
fi;
done
ruleTimes=`expr $times - 1`;
totalIdle=`echo $total / $ruleTimes | bc`;
echo `echo 100.00 - $totalIdle | bc`;
}
getNetUseRatio()
{
monitorEth=""
monitorEths=`ifconfig |grep 'Link encap:'|awk '{print $1}'`
for tmpMonitorEth in $monitorEths
do
tmpIP="`/sbin/ifconfig|sed -n 'N;/^'$tmpMonitorEth'/p' |grep 'inet addr:'|awk -F: '{print $2}'|awk '{print $1}'`"
if [ "X$localhostIP" == "X$tmpIP" ]
then
monitorEth=$tmpMonitorEth
fi
done
ethBandWidth="`ethtool ${monitorEth}|grep Speed|awk '{print $2}'|sed 's/[^0-9]//g'`"
RXpre=$(ifconfig ${monitorEth} | grep bytes | awk '{print $2}'| awk -F":" '{print $2}')
TXpre=$(ifconfig ${monitorEth} | grep bytes | awk '{print $6}' | awk -F":" '{print $2}')
#统计10秒总流量
sleep 10
RXnext=$(ifconfig ${monitorEth} | grep bytes | awk '{print $2}'| awk -F":" '{print $2}')
TXnext=$(ifconfig ${monitorEth} | grep bytes | awk '{print $6}' | awk -F":" '{print $2}')
Totaltrans=$(((${RXnext}-${RXpre}+${TXnext}-${TXpre})*8))
NetUseRatio=`echo "scale=4;${Totaltrans}*10/1024/1024/${ethBandWidth}"|bc`
echo $NetUseRatio
}
getIOUseRatio()
{
#iosta取5次统计,去掉第一个
#统计次数
statCount=5
v_ioutils=`iostat -d -x 1 $statCount|grep -v "Device:\|Linux"| awk '{print $NF}'`
i=0;
total=`echo $v_ioutils|wc -w `
tmputil=0.0
#去掉iostat命令第一次取的数据个数
count=`echo $total/$statCount + 1|bc`
for v_ioutil in $v_ioutils
do
i=`expr $i + 1`;
if [ 1 == `echo "$i < $count"|bc` ];then
continue;
fi
if [ 1 == `echo "$v_ioutil > $tmputil"|bc` ]; then
tmputil=$v_ioutil
fi
done
echo $tmputil
}
getMemUseRatio()
{
memUseRatio=0
if [ "$monitorType" == "1" ] ;then
total=`free -m|grep "Mem:"|awk '{print $2}'`
used=`free -m|grep "Mem:"|awk '{print $3}'`
memUseRatio=`echo "scale=4;${used}*100/$total"|bc`
else
pid=`ps -ef |grep java|grep ${monitorpath}|awk '{print $2}'`
maxMem=`jmap -heap ${pid}| grep MaxHeapSize| awk '{print $3}'`
memUsedData=`jmap -heap ${pid}| grep "% used"`
memUseRatio=`echo $memUsedData|awk -F"%" '{print $5}'|awk '{print $2}'`
memUseRatio=`echo "scale=4;${memUseRatio}/1"|bc`
fi
echo $memUseRatio
}
cpu_useratio=`getCPUUseRatio`
net_useratio=`getNetUseRatio`
io_useratio=`getIOUseRatio`
mem_useratio=`getMemUseRatio`
echo "`hostname`|${monitorProgramName}|"`date "+%Y-%m-%d %T"`"|${cpu_useratio}|${mem_useratio}|${io_useratio}|${net_useratio}" >> ${sysMonitorDataFile}
#set connect timeout 5s
clearResult=`curl --connect-timeout 5 "http://127.0.0.1:"${portalMSPort}"/sys/sysMonitoerDataGratherAction"\!"saveSysMonitoerData.do?sysMonitorDataFile=${sysMonitorDataFile}" 2> /dev/null`
if [ "000000" == "${clearResult}" ]; then
echo "[INFO]: save system monitoer data success."
else
resultMsg=`echo ${clearResult} | awk -F= '{print $2}'`
if [ -z "${resultMsg}" ]; then
echo "[ERROR]: save system monitoer data fail."
else
echo "[ERROR]: ${resultMsg}"
fi
fi
portalMSPort="8881"
localhostIP="172.21.11.97"
monitorProgramName=portalMS
monitorpath="/usr/local/portal/jboss5/bin/run.jar"
sysMonitorDataFile="/usr/local/portalMS/jboss5/bin/sysMonitorData.txt"
###监控进程类型:0:java 1:c
monitorType=0
getCPUUseRatio()
{
times=5
cpuIdleInfo=`top -b -n $times | grep 'Cpu(s)' | awk -F' ' '{print $5}'`;
i=0;
total=0;
for eachInfo in $cpuIdleInfo
do
i=`expr $i + 1`;
#first rows not get
if [ "X$i" == "X1" ]; then
continue;
fi;
eachIdle=`echo $eachInfo | cut -d"%" -f1`;
flag=`echo $eachInfo | cut -d"%" -f2`;
if [ "X$flag" == "Xid," ]; then
total=`echo $total + $eachIdle | bc`;
fi;
done
ruleTimes=`expr $times - 1`;
totalIdle=`echo $total / $ruleTimes | bc`;
echo `echo 100.00 - $totalIdle | bc`;
}
getNetUseRatio()
{
monitorEth=""
monitorEths=`ifconfig |grep 'Link encap:'|awk '{print $1}'`
for tmpMonitorEth in $monitorEths
do
tmpIP="`/sbin/ifconfig|sed -n 'N;/^'$tmpMonitorEth'/p' |grep 'inet addr:'|awk -F: '{print $2}'|awk '{print $1}'`"
if [ "X$localhostIP" == "X$tmpIP" ]
then
monitorEth=$tmpMonitorEth
fi
done
ethBandWidth="`ethtool ${monitorEth}|grep Speed|awk '{print $2}'|sed 's/[^0-9]//g'`"
RXpre=$(ifconfig ${monitorEth} | grep bytes | awk '{print $2}'| awk -F":" '{print $2}')
TXpre=$(ifconfig ${monitorEth} | grep bytes | awk '{print $6}' | awk -F":" '{print $2}')
#统计10秒总流量
sleep 10
RXnext=$(ifconfig ${monitorEth} | grep bytes | awk '{print $2}'| awk -F":" '{print $2}')
TXnext=$(ifconfig ${monitorEth} | grep bytes | awk '{print $6}' | awk -F":" '{print $2}')
Totaltrans=$(((${RXnext}-${RXpre}+${TXnext}-${TXpre})*8))
NetUseRatio=`echo "scale=4;${Totaltrans}*10/1024/1024/${ethBandWidth}"|bc`
echo $NetUseRatio
}
getIOUseRatio()
{
#iosta取5次统计,去掉第一个
#统计次数
statCount=5
v_ioutils=`iostat -d -x 1 $statCount|grep -v "Device:\|Linux"| awk '{print $NF}'`
i=0;
total=`echo $v_ioutils|wc -w `
tmputil=0.0
#去掉iostat命令第一次取的数据个数
count=`echo $total/$statCount + 1|bc`
for v_ioutil in $v_ioutils
do
i=`expr $i + 1`;
if [ 1 == `echo "$i < $count"|bc` ];then
continue;
fi
if [ 1 == `echo "$v_ioutil > $tmputil"|bc` ]; then
tmputil=$v_ioutil
fi
done
echo $tmputil
}
getMemUseRatio()
{
memUseRatio=0
if [ "$monitorType" == "1" ] ;then
total=`free -m|grep "Mem:"|awk '{print $2}'`
used=`free -m|grep "Mem:"|awk '{print $3}'`
memUseRatio=`echo "scale=4;${used}*100/$total"|bc`
else
pid=`ps -ef |grep java|grep ${monitorpath}|awk '{print $2}'`
maxMem=`jmap -heap ${pid}| grep MaxHeapSize| awk '{print $3}'`
memUsedData=`jmap -heap ${pid}| grep "% used"`
memUseRatio=`echo $memUsedData|awk -F"%" '{print $5}'|awk '{print $2}'`
memUseRatio=`echo "scale=4;${memUseRatio}/1"|bc`
fi
echo $memUseRatio
}
cpu_useratio=`getCPUUseRatio`
net_useratio=`getNetUseRatio`
io_useratio=`getIOUseRatio`
mem_useratio=`getMemUseRatio`
echo "`hostname`|${monitorProgramName}|"`date "+%Y-%m-%d %T"`"|${cpu_useratio}|${mem_useratio}|${io_useratio}|${net_useratio}" >> ${sysMonitorDataFile}
#set connect timeout 5s
clearResult=`curl --connect-timeout 5 "http://127.0.0.1:"${portalMSPort}"/sys/sysMonitoerDataGratherAction"\!"saveSysMonitoerData.do?sysMonitorDataFile=${sysMonitorDataFile}" 2> /dev/null`
if [ "000000" == "${clearResult}" ]; then
echo "[INFO]: save system monitoer data success."
else
resultMsg=`echo ${clearResult} | awk -F= '{print $2}'`
if [ -z "${resultMsg}" ]; then
echo "[ERROR]: save system monitoer data fail."
else
echo "[ERROR]: ${resultMsg}"
fi
fi
相关文章推荐
- Linux两台服务器之间复制文件及免密码登录的方法
- Linux两台服务器之间复制文件及免密码登录的方法
- Linux远程服务器之间下拷贝文件不输入密码
- 使用scp在linux主机之间无密码复制文件/目录
- linux服务器之间拷贝文件 scp
- Linux 与 Linux服务器之间文件传输方式之SCP
- 两台linux主机之间传送文件
- 配置NFS实现Linux服务器之间的文件共享
- 多linux服务器之间实现文件自动复制(脚本)
- linux 服务器传文件如何不用输密码?
- linux rsync 不同服务器之间的文件备份同步
- linux传送文件到其他服务器
- Linux 不同服务器间传递文件 不需要输入密码
- linux sra密钥 (服务器之间交互不需要输入密码)
- linux多服务器之间的目录文件同步
- scp在Linux主机之间复制文件/目录不用输入密码
- Linux中使用rsync实现多服务器之间文件同步问题
- linux下使用scp在服务器之间拷贝文件
- linux 服务器之间拷贝文件
- 配置linux服务器之间ssh不用密码访问