此脚本用来读懂
#!/bin/bash
#把采集结果传到xxx服务器
remoteusername="monitor"
resultdate=`date +"%Y%m%d"`
ipadd=$(LC_ALL=C /sbin/ifconfig|grep "inet addr:"|grep -v "127.0.0.1"|cut -d: -f2|awk '{print $1}'|head -1)
if [ A$ipadd = A ];then
ipadd=$(LC_ALL=C /sbin/ifconfig | grep inet | grep -v inet6 | grep -v 127 | sed 's/^[ \t]*//g' | cut -d ' ' -f2)
fi
resultpath="/home/$remoteusername/$resultdate/$ipadd"
su - $remoteusername -c "ssh -p 22 $remoteusername@192.168.55.80 'mkdir -p $resultpath' "
su - $remoteusername -c "scp -P 22 /opt/logagent/process/*result.txt $remoteusername@192.168.55.80:$resultpath"
#到xx服务器获取最新脚本
su - $remoteusername -c "scp -P 22 $remoteusername@192.168.55.80:/home/monitor/process/axsh_process.sh /home/monitor/axsh_process1.sh"
if [ -f "/home/monitor/axsh_process1.sh" ];then
currentmd5=$(md5sum /home/monitor/axsh_process1.sh |awk -F " " '{ print $1 }')
lastmd5=$(md5sum /opt/logagent/process/axsh_process.sh |awk -F " " '{ print $1 }')
if [ $currentmd5 != $lastmd5 ];then
rm -rf /opt/logagent/process/axsh_process.sh
mv /home/monitor/axsh_process1.sh /opt/logagent/process/axsh_process.sh
chown root:root /opt/logagent/process/axsh_process.sh
chmod 700 /opt/logagent/process/axsh_process.sh
elif [ $currentmd5 = $lastmd5 ];then
rm -rf /home/monitor/process/axsh_process1.sh
exit
fi
else
exit
fi