原!linux机器 配置自动scp脚本

 方式一:

1.安装相关依赖包

yum install -y tcl tclx tcl-devel
yum -y install expect

2.脚本 scp.sh

#!/usr/bin/expect

#获取输入参数
set f1 [lindex $argv 0]
set f2 [lindex $argv 1]
set dir [lindex $argv 2]

spawn scp /var/log/usermonitor/$f1   USER@IP:/apprun/test/$dir
expect "*password*"
 send "$PASSWD "
 sleep 1

spawn scp /var/log/usermonitor/$f2   USER@IP:/apprun/test/$dir

expect "*password*"
 send "$PASSWD "
 sleep 1

 expect eof

方式二:

A. Tcl 安装 
主页: http://www.tcl.tk
下载地址: http://www.tcl.tk/software/tcltk/downloadnow84.tml

1.下载源码包
wget http://nchc.dl.sourceforge.net/sourceforge/tcl/tcl8.4.11-src.tar.gz

2.解压缩源码包
tar xfvz tcl8.4.11-src.tar.gz

3.安装配置
cd tcl8.4.11/unix
./configure --prefix=/usr/tcl --enable-shared
make
make install

安装完毕以后,进入tcl源代码的根目录,把子目录unix下面的tclUnixPort.h copy到子目录generic中
暂时不要删除tcl源代码,因为expect的安装过程还需要用。

B. expect 安装 (需Tcl的库)
主页: http://expect.nist.gov/

1.下载源码包
wget http://sourceforge.net/projects/expect/files/Expect/5.45/expect5.45.tar.gz/download

2.解压缩源码包
tar xzvf expect5.45.tar.gz

3.安装配置
cd expect5.45
./configure --prefix=/usr/expect --with-tcl=/usr/tcl/lib --with-tclinclude=../tcl8.4.11/generic

make
make install
ln -s /usr/tcl/bin/expect /usr/expect/bin/expect

 
原文地址:https://www.cnblogs.com/wuyun-blog/p/13389044.html