利用定时crond自动上传文件:
#!/bin/sh
#########################################################################################################
## 上传日志 xxlog-xxxxxxxx 脚本 , PC需开启tftpd
## DSTIP : 电脑IP地址
## FREQUENCE: 1 分钟
#########################################################################################################
LOGFILE="/tmp/netmonitor/WF2log-"$(date +%Y%m%d-%H%M)
DSTIP="192.168.10.184"
CRONTFILE="/data/tftp2pc_crontab"
FREQUENCE=1
run_crond()
{
CRONTAB_FILE="/var/spool/cron/crontabs/user"
[ ! -e /var/spool/cron/crontabs ] && mkdir -p /var/spool/cron/crontabs
[ -e ${CRONTAB_FILE} ] && rm -rf ${CRONTAB_FILE}
[ -e /data/*crontab ] && rm -rf /data/*crontab
minute=0
hour=0
while [ $hour -lt 24 ]
do
while [ $minute -lt 60 -a $hour = 16 -a $week = 1 ]
do
echo "${minute} ${hour} * * * /data/tftp2pc.sh" >> ${CRONTFILE}
let minute+=$FREQUNCE
done
let hour+=1
minute=0
done
ls /data/*_crontab > /dev/null 2>&1
if [ $? != 0 ];then
return 0
else
ls /data/*_crontab |
while read file_name;
do
cat $file_name >> ${CRONTAB_FILE}
done
fi
killall -9 crond > /dev/null 2>&1
crond start
}
run_tftp2pc()
{
echo "$(date)" > ${LOGFILE}
echo "--------------------------------------------" >> ${LOGFILE}
cat /proc/meminfo | grep Mem >> ${LOGFILE}
echo "--------------------------------------------" >> ${LOGFILE}
top -n 1 >> ${LOGFILE}
echo "--------------------------------------------" >> ${LOGFILE}
ps >> ${LOGFILE}
num=`echo $LOGFILE | tr -cd '/' | wc -c`
let num++
TMPLOGFILE=`echo $LOGFILE | cut -d '/' -f$num`
cd `echo $LOGFILE | sed "s/$TMPLOGFILE//"` && tftp -pl ${TMPLOGFILE} ${DSTIP}
rm -rf ${LOGFILE}
}
[ "x$1" = "xcrond" ] && run_crond
run_tftp2pc