需求:
将10.10.50.16:/home/build下的debug.tcl, good.tcl best.tcl 远程拷贝到10.10.51.16:/home/build下
方法:
1)将debug.tcl, good.tcl best.tcl 分行写入到filename中
eg. cat filename
# file name
debug.tcl
good.tcl
best.tcl
2)在shell脚本中调用expect实现远程拷贝, 代码如下:
#!/bin/sh
for _item in `cat filename | grep -v '#'`;do
expect -c "
set timeout 60
spawn scp $_item 10.10.51.16:/home/build
expect {
\"*yes/no*\" {send \"yes\r\"}
\"*assword:\" {send \"build\r\"}
}
expect eof
"
echo "$_item is ok..."
done;
注意:
1)运行上述shell脚本的机器上必须正确安装了expect