1.expect安装
yum install -y tclx tcl-devel
yum install -y expect
2.编写sendpkt.sh
#!/usr/bin/expect
spawn scp -r /home/pkt/2009.cap root@192.168.0.4:/home/
expect "*password*"
send "root\r"
expect eof
注意:密码尽量去掉特殊字符,有特殊字符需要转义
3.隔10秒执行一次sendpkt.sh
crontab -e
输入:
* * * * * /root/sendpkt.sh
* * * * * sleep 10 && /root/sendpkt.sh
* * * * * sleep 20 && /root/sendpkt.sh
* * * * * sleep 30 && /root/sendpkt.sh
* * * * * sleep 40 && /root/sendpkt.sh
* * * * * sleep 50 && /root/sendpkt.sh
* * * * * sleep 60 && /root/sendpkt.s
注意:-e模式下不需要输入用户名